【发布时间】:2012-12-13 00:37:56
【问题描述】:
在 iPhone 模拟器和 iPhone 3GS (iOS 6) 上,我都无法将方向设置为纵向倒置。我只有一个 ViewController。我已经在其中添加了这段代码:
-(BOOL) shouldAutorotate{
return YES;
}
-(UIInterfaceOrientation) preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortraitUpsideDown;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
if (toInterfaceOrientation==UIInterfaceOrientationPortrait || toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) {
return YES;
}
return NO;
}
我也将此添加到 AppDelegate.m:
-(NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
我还检查了 plist 文件,两个方向都存在。在我的故事板上,Simulated Metrics Orientation 设置为 Inferred。我在 applicationDidFinishLaunchingWithOptions 中什么都不做,除了返回 YES。我刚刚在这个 ViewController 中添加了一个 UIImageView。是否有可能使这种定向工作?
【问题讨论】:
-
supportedInterfaceOrientationsForWindow: 应该返回 UIInterfaceOrientationMask。
标签: iphone ios6 storyboard portrait interface-orientation