[英]iPad iOS7 Orientation Problems
我有一个应用程序,当使用以下方法更改方向时会更改视图:[[UIApplication sharedApplication] statusBarOrientation]。 在iPhone上,它可以工作,但在iPad上,它给我的是风景而不是肖像,而肖像是风景。
这是我用来计算相关框架的代码:
编辑:使用rob5408的建议。 更改为使用UI_USER_INTERFACE_IDIOM()。
+ (CGRect)getRelevantFrame {
//Get orientation
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { //iPhone/iPod
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
return [self frameiPhoneLandscape];
}
else {
return [self frameiPhonePortrait];
}
} else if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { //iPad
if(interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
NSLog(@"iPad Landscape");
return [self frameiPadLandscape];
}
else {
NSLog(@"iPad Portrait");
return [self frameiPadPortrait];
}
}
return CGRectMake(0, 0, 0, 0);
}
这是我使用的通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
这是我用来阅读方向变化的代码:
- (void) didRotate:(NSNotification *)notification
{
NSLog(@"Parent: %@", self.parentController);
if(self.parentController) {
[self setFrame:[TASFrames getRelevantFrame]];
}
}
我将代码转移到一个新项目。 现在,它可以按预期运行。 不知道为什么会这样。 代码没有改变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.