0

我有两个视图(视图 1 和视图 2)。view1 包含一个按钮,当我单击此按钮时,我转到视图 2。我想显示具有方向纵向和横向的 view2。对于 view2,我创建了 2 个 UiviewController 一个用于横向,第二个用于纵向,并且具有相同的 Class.but 不起作用。有人知道吗?

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

1 回答 1

0

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

这里简单的场景,

创建 2 个视图

  1. 肖像 &&
  2. 风景视图,根据您的要求。

遵循这样的事情。

-(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;
}
于 2013-07-19T09:36:04.610 回答