我有这个代码,它在iOS 5上完美运行,但在iOS 6上没有帮助
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
return (orientation != UIDeviceOrientationPortrait) &&
(orientation != UIDeviceOrientationPortraitUpsideDown);
}
答案 0 :(得分:2)
试试这个:
首先在viewDidLoad
函数内部使用以下代码:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
然后,我创建的函数将接收两行代码的通知:
- (void)orientationChanged:(NSNotification *)object{
NSLog(@"orientation change");
UIDeviceOrientation deviceOrientation = [[object object] orientation];
if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown){
if(deviceOrientation ==UIInterfaceOrientationPortrait){
NSLog(@"Changed Orientation To Portrait");
// Handle your view.
}
}else{
if(deviceOrientation ==UIInterfaceOrientationLandscapeLeft){
NSLog(@"Changed Orientation To Landscape left");
// Handle your view.
}else{
NSLog(@"Changed Orientation To Landscape right");
// Handle your view.
}
}
}
我希望我的回答会有所帮助。欢呼声。
答案 1 :(得分:1)
在iOS6中,不推荐使用“shouldAutorotateToInterfaceOrientation”方法。尝试在plist文件中设置方向。