在故事板中使用ios 5进行定位

时间:2013-07-19 09:20:20

标签: ios orientation landscape

我有两个视图(视图1和视图2)。 view1包含一个按钮,当我点击这个按钮时,我去查看2.我想要显示view2的方向纵向和横向。对于view2我创建2个UiviewController一个用于横向和seconde用于纵向方向和相同的Class.but不起作用。任何人都有任何想法?

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
     return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

1 个答案:

答案 0 :(得分:0)

为什么你需要 TWO ViewControllers只是为了定位......?

HEre Simple scenario,

  

创建2个视图

  1. Portrait&&
  2. 景观视图,根据您的要求。
  3. 遵循这样的事情。

    -(BOOL)shouldAutorotate{
        return YES;
    }
    
    - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [self orientationChanged:toInterfaceOrientation];
    }
    
    -(void)orientationChanged:(UIInterfaceOrientation)orientation{
        NSLog(@"orientation change");
       // UIDeviceOrientation deviceOrientation = [[object object] orientation];
    
        if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown){
            NSLog(@"Changed Orientation To Portrait");
            self.viewPortrait.hidden = NO;
            self.viewLandscape.hidden = YES;
        }
    
    else if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
        NSLog(@"Changed Orientation To Landscape");
    
        self.viewPortrait.hidden = YES;
        self.viewLandscape.hidden = NO;
        }  
    }
    
      

    并且您应该设置所需的所有方向。

    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }