在 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。是否有可能使这种定向工作?