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