0
我正在开发一个启动屏幕并随后移至登录屏幕的iPad应用程序。我的应用应该支持所有的方向,并且iOS 4.3及更高版本。要做到这一点,我说的plist中的四个方向,和下面的代码在应用程序委托:“[[UIApplication sharedApplication] statusBarOrientation];在第一次调用时出现错误值”
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
// Override point for customization after application launch
SplashViewController *aController = [[SplashViewController alloc] initWithNibName:@"SplashView" bundle:nil];
self.mainViewController = aController;
[aController release];
mainViewController.view.frame = [UIScreen mainScreen].bounds;// no effect
[window setFrame:[[UIScreen mainScreen] bounds]]; //no effect
//[window addSubview:[mainViewController view]];
[window setRootViewController:mainViewController];
return YES;
}
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
在闪屏
- (void) loadView {
[super loadView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (BOOL)shouldAutorotate{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
- (void) orientationChanged
{
UIInterfaceOrientation interfaceOrientation =[[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
NSLog(@"Portrait");
else
NSLog(@"Landscape");
}
在这里我得到了正确的方向,但转动时,我得到一个倒转的结果,我得到了肖像的风景和风景的肖像。我试图将代码转换是这样的:
- (void) orientationChanged
{
UIInterfaceOrientation interfaceOrientation =[[UIApplication sharedApplication] statusBarOrientation];
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
NSLog(@"Landscape");
else
NSLog(@"Portrait");
}
我得到的第一个结果错了,之后的结果是正确的。你能帮我吗? 请注意,我已经放了一些元素来测试和测试来与相同的结果。 谢谢
但从一个视图导航到另一个时仍然是同样的问题 – 2013-02-14 10:20:16