0

I have four controllers for the tab bar and it's views, when I rotate phone I want it to call the method shouldAutorotateToInterfaceOrientation for only one of the controllers but it calls the method for all of them.

How can I call shouldAutorotateToInterfaceOrientation for only one of the controllers?

4

2 回答 2

1

您不会“调用”这些方法,这些方法是为从 UIViewController 继承的任何类调用的方法。
没有理由不希望他们不被调用。
您可以做的是决定为您的任何控制器覆盖这些方法中的任何一个。
该方法返回一个布尔值,如果返回 true,则视图正在旋转,如果返回 false,则不是。

您还可以根据方向决定返回 YES/NO,以支持一种特定的方向

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

在这种情况下,仅当新方向为纵向时才会旋转视图。

于 2012-05-03T01:20:09.663 回答
0

谢谢JP Hribovsek,我解决了这个问题,beginGeneratingDeviceOrientationNotifications当设备的方向改变时通知我。例如:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] addObserver: self 
                                         selector: @selector(deviceRotate:) 
                                             name: UIDeviceOrientationDidChangeNotification 
                                           object: nil];

-(void) deviceRotate: (NSNotification*) notification
{
    UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {    
        NSlog(@"Landscape");    
    }
}
于 2012-05-03T18:35:12.653 回答