我目前正在构建一个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
答案 0 :(得分:1)
尝试从此
更改您的方法-(NSInteger)supportedInterfaceOrientations:(UIWindow *)window{
}
到这个
-(NSUInteger)supportedInterfaceOrientations{
}
修改
尝试在这样的导航控制器中调用您的视图:
UIViewController *yourViewController = [[UIViewController alloc] init];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:yourViewController];
nc.navigationBarHidden = YES;
[self.navigationController presentModalViewController:nc animated:NO];
[self.navigationController dismissModalViewControllerAnimated:NO];
修改强>
#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]];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:_viewController];
nc.navigationBarHidden = YES;
_window.rootViewController = nc;
[_window makeKeyAndVisible];
}
- (void)dealloc {
[_viewController release];
[_window release];
[super dealloc];
}
@end
答案 1 :(得分:1)
尝试添加:
_window.rootViewController = _viewController;
编辑:无论如何,您的代码看起来像使用“已弃用”的样式。我建议为iOS6设置一个新项目并使用它的模板。它在iOS5上运行但iOS发生了变化。
答案 2 :(得分:0)