[英]i want to know device orientation when the view will appear IOS 6
I want to know device orientation when the view will appear. 我想知道视图出现时的设备方向。 Previously it was possible using the
shouldAutorotateToInterfaceOrientation
method but in IOS 6 it is deprecated. 以前可以使用
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;
}
I checked all the post ie making rootviewcontroller and 我检查了所有帖子,即制作rootviewcontroller和
- (BOOL)shouldAutorotate {
return NO;
}// this method is not called
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Try using 尝试使用
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
instead of 代替
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
refer http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html for details. 有关详细信息,请参阅http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html 。
Create category of UINavigationController and add below code @implementation UINavigationController (Rotation_IOS6) 创建UINavigationController的类别并添加以下代码@implementation UINavigationController(Rotation_IOS6)
-(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; - (BOOL)shouldAutorotate {return [[self.viewControllers lastObject] shouldAutorotate]; }
}
-(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; - (NSUInteger)supportedInterfaceOrientations {return [[self.viewControllers lastObject] supportedInterfaceOrientations]; }
}
@end @结束
了解设备方向的最佳选择是
[[UIApplication sharedApplication] statusBarOrientation]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.