横向きで起動したいインターフェースがあります。ユーザーがデバイスを縦向きに回転させたときに起動した後、日表示のカレンダーを表示しています。横向きに戻ると、カレンダーは閉じられます。私のアプリケーション ユーザー インターフェイスは横向きで正しく表示され、カレンダーは縦向きで正しく表示され、すべてがどの向きでもうまく機能します。
問題は、ユーザーが起動時に iPhone を横向きに持っている場合です。何をしても、ランドスケープモードのユーザーインターフェイスで起動できません。私の UIDeviceOrientationDidChangeNotification メソッドは 2 回起動します。1 回目は [UIDevice currentDevice].orientation が横向きで、2 回目は縦向きです。最終的な結果として、ユーザー インターフェイスが縦向きモードに回転し、日ビューが表示されます。私が欲しいものではありません。ユーザーが物理的にデバイスを横向きから縦向きに回転させるまで、ユーザー インターフェイスを横向きのままにしておきたいです。
ユーザーがデバイスを縦向きに保持しているときに、横向き [UIDevice currentDevice].orientation で起動する理由がわかりません。
これが私のコードがviewControllerでどのように見えるかです...
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if ((interfaceOrientation == UIDeviceOrientationPortrait)|| (interfaceOrientation == UIDeviceOrientationPortraitUpsideDown)) {
return NO;
}
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
showingCalendar = NO;
initializing=YES;
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
-(void)didRotate:(NSNotification *)notification {
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if ((deviceOrientation == UIDeviceOrientationPortrait) || (deviceOrientation == UIDeviceOrientationPortraitUpsideDown)) {
if ((!showingCalendar) && (!initializing)) {
showingCalendar = YES;
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
GCCalendarPortraitView *calendar = [[[GCCalendarPortraitView alloc] init] autorelease];
navigationController = [[UINavigationController alloc] initWithRootViewController:calendar];
[self presentModalViewController:navigationController animated:YES];
}
}else if ((deviceOrientation == UIDeviceOrientationLandscapeRight) || (deviceOrientation == UIDeviceOrientationLandscapeLeft)) {
if (showingCalendar) {
showingCalendar = NO;
if (deviceOrientation == UIDeviceOrientationLandscapeRight){
[self dismissModalViewControllerAnimated:YES];
}else if (deviceOrientation == UIDeviceOrientationLandscapeLeft){
[self dismissModalViewControllerAnimated:YES];
}
}else {
initializing = NO;
}
}
}