簡體   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