我想知道视图出现时的设备方向。
以前可以使用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;
}
答案 0 :(得分:1)
尝试使用
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
而不是
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
答案 1 :(得分:1)
创建UINavigationController的类别并添加以下代码@implementation UINavigationController(Rotation_IOS6)
- (BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; }
- (NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; }
@end
答案 2 :(得分:0)
了解设备方向的最佳选择是
[[UIApplication sharedApplication] statusBarOrientation]