0

我想知道视图何时出现的设备方向。以前可以使用该shouldAutorotateToInterfaceOrientation方法,但在 IOS 6 中已弃用。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if (interfaceOrientation==UIInterfaceOrientationPortrait ||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown ) {
        DashBtn.hidden=NO;
    }
    else
    {
        DashBtn.hidden=YES;
        if (self.popoverControllerMain) {
            [self.popoverControllerMain dismissPopoverAnimated:YES];
        }


    }
    return YES;
}

我检查了所有的帖子,即制作 rootviewcontroller 和

- (BOOL)shouldAutorotate {
    return NO;
}// this method is not called

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
4

3 回答 3

1

尝试使用

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

代替

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

有关详细信息,请参阅http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

于 2012-10-30T07:33:07.437 回答
1

创建 UINavigationController 的类别并添加以下代码 @implementation UINavigationController (Rotation_IOS6)

-(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; }

-(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; }

  • (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; }

@结尾

于 2012-10-30T09:14:34.050 回答
0

了解设备方向的最佳选择是

[[UIApplication sharedApplication] statusBarOrientation]
于 2012-10-30T07:35:14.653 回答