我希望在视图出现IOS 6时知道设备方向

时间:2012-10-30 07:22:32

标签: iphone

我想知道视图出现时的设备方向。 以前可以使用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;
}

3 个答案:

答案 0 :(得分: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了解详情。

答案 1 :(得分: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]; }

@end

答案 2 :(得分:0)

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

[[UIApplication sharedApplication] statusBarOrientation]