[英]iOS7 - AutoRotate is not getting invoked
球隊,
我正在做一個支持項目,並且我對iPhone有基本的了解。 當我在設備中更改方向時,以下方法都不會在更改方向時被調用。
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
// your code for portrait mode
}
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait;
//return here which orientation you are going to support
}
我通過presentViewController推送屏幕,並且在推送屏幕之前調用了上面的方法,但是在推送屏幕后以及更改方向時什么都沒有。
另外,我嘗試按照以下說明創建類別,但我收到viewController not found錯誤,不確定我在這里缺少什么...
在IOS7中,如果使用UINavigationController,則旋轉處理方式不同!
看到UINavigationController,可以看到它是UIViewController的子類,那么那就是在他上面列出了輪換的處理方法; 因此,我們還需要使用UINavigationController進行旋轉處理,
我的方法是將類別添加到UINavigationController,這樣做。
在類別中。 M寫
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
任何幫助是極大的贊賞!
對我來說,其他兩個功能也可以使用,但是您可以嘗試使用下面的委托
從Apple Docs:
在用戶界面開始旋轉之前發送給視圖控制器。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
持續時間:(NSTimeInterval)duration
用戶界面旋轉后發送到視圖控制器:
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.