テンプレートアプリを作成しています。デバイスの回転/向きに問題があります。私は appDelegate didFinishLaunching に以下を持っています:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
と私の VC viewDidLoad で:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
...
//add the title bar
titleBar = [[OAI_TitleBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 1024.0, 50.0)];
titleBar.titleBarTitle = @"OAI Template";
titleBar.hasAccount = YES;
titleBar.hasReset = YES;
titleBar.hasHome = YES;
[titleBar buildTitleBar];
[self.view addSubview:titleBar];
これは私の deviceOrientationDidChange メソッドです:
//rotate the vc view
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
[self.view setFrame:CGRectMake(0.0, 0.0, 1024.0, 768.0)];
} else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) {
[self.view setFrame:CGRectMake(0.0, 0.0, 768.0, 1024.0)];
}
//call the rotation management methods of various classes
[titleBar adjustForRotation:orientation];
}
これは、デバイスを回転させると正常に機能し、ビューは期待どおりに調整されます。しかし、アプリを起動すると、x、y 座標が間違っています。 {{20, 0}, {748, 1024}} です
タイトルバー フレームは、横向きと縦向きの場合は {{20, 0}, {748, 1024}} です (コーディングしたとおりです)。
ただし、シミュレーターとデバイスで表示される内容は大幅に異なります。上部に黒いバー (高さ 50 ピクセル程度) があり、左側にロゴがあり、その後にいくつかのボタンがあり、アプリのタイトルが右側に配置されています。下の画像からわかるように、アプリがいずれかの方向で起動すると、x/y 座標が 0/20 に近くなりません。どんな助けでも大歓迎です。
私には、アプリが横向きで起動すると縦向きで表示され、縦向きで起動すると、表示は正しいものの、約 20.0f ほどずれているように見えます。どんな助けでも大歓迎です。