繁体   English   中英

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

[英]i want to know device orientation when the view will appear IOS 6

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

尝试使用

-(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

创建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]; }

@结束

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

[[UIApplication sharedApplication] statusBarOrientation]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM