スプラッシュ画面から始まり、ログイン画面に移動する iPad アプリに取り組んでいます。私のアプリは、すべての向きと iOS 4.3 以降をサポートする必要があります。そのために、plist に 4 つの向きを追加し、アプリ デリゲートに次のコードを追加しました。
- (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");
}
最初の結果は間違っていますが、その後は正しい結果になります。手伝ってくれますか?テストするいくつかの uielement を配置しましたが、テストの結果は同じであることに注意してください。ありがとうございました