我正在开发一个iOS应用程序,它只支持横向左右屏幕方向。我已经通过多种方式进行了指定:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation); //iOS 5 compatibility.
}
-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscape; //iOS 6
}
-(BOOL)shouldAutorotate{
return YES;
}
我已在应用的Info.plist中将支持的方向指定为仅横屏。当我在设备上运行应用程序(甚至在模拟器中),我知道根视图处于横向方向(切换器位于屏幕的长边上,通知中心也是如此),但是内容仍然从屏幕左上角开始,就像是纵向模式,而不是我想要的左下角或右上角。我不知道是什么原因导致内容无法随父视图旋转,因为这段代码在iOS 5上可以工作,但在iOS 6上却不能。
编辑:这里有一张截图。
编辑:这是我的main.m文件:
#import <UIKit/UIKit.h>
int main(int argc, char **argv) {
NSAutoreleasePool *p = [[NSAutoreleasePool alloc] init];
int ret = UIApplicationMain(argc, argv, @"ClockApplication", @"ClockApplication");
[p drain];
return ret;
}
这是我的ClockApplication.mm文件:
#import "RootViewController.h"
@interface ClockApplication: UIApplication <UIApplicationDelegate> {
UIWindow *_window;
RootViewController *_viewController;
}
@property (nonatomic, retain) UIWindow *window;
@end
@implementation ClockApplication
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_viewController = [[RootViewController alloc] init];
[_window addSubview:_viewController.view];
[_window makeKeyAndVisible];
}
- (void)dealloc {
[_viewController release];
[_window release];
[super dealloc];
}
@end