클리너 방법은 회전 UIInterfaceOrientation을 사용하지 않는 것입니다.
이유는 인터페이스 또는보기 1이 실제로 회전하기 때문입니다. 즉,보기 2를 제거한 후에 다시 표시하려면 다시 회전해야합니다.
이를 보완하기 위해 간단하게 UIDeviceOrientation 알림을 구독합니다. 미묘하게 다른. View 1은 자동 회전을 지원하지 않아도이 방법을 사용할 수 있습니다.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
가 그럼 그냥 메소드 detectOrientation을 정의 :
-(void) detectOrientation {
if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) ||
([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
//load view 2
} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
// load view 1
}
}
이제 귀하의 의견 중 어느 것도 autoratation을 지원할 필요가있는 viewDidLoad에서 다음 코드를 입력합니다! 당신은 그러나로드하기 전에 뷰 2 변환을 수행해야합니다
-(void) transformView2ToLandscape {
NSInteger rotationDirection;
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
if(currentOrientation == UIDeviceOrientationLandscapeLeft){
rotationDirection = 1;
}else {
rotationDirection = -1;
}
CGRect myFrame = CGRectMake(0, 0, 480, 300);
CGAffineTransform transform = [[self view2] transform];
transform = CGAffineTransformRotate(transform, degreesToRadians(rotationDirection * 90));
[[self view2] setFrame: myFrame];
CGPoint center = CGPointMake(myFrame.size.height/2.0, myFrame.size.width/2.0);
[[self view2] setTransform: transform];
[[self view2] setCenter: center];
}
그게 어떻게 내보기에 자동 회전을 지원하지 않고 회전 오 의견을 교환합니다.
shouldAutorotateToInterfaceOrientation 메소드를 추가하기 위해 초기 tabBarController를 서브 클래스 화해야합니까? 이 탭바 컨트롤러는 IB와 응용 프로그램 대리인의 코드 몇 줄을 사용하여 설정되었습니다. 모든 단계를 수행했지만 didRotateFromInterfaceOrientation이 호출되지 않았습니다. –
자, tabBarController를 서브 클래 싱하고 shouldAutorotateToInterfaceOrientation을 추가하면 모든 것이 작동합니다. 당신의 도움을 주셔서 대단히 감사합니다. 친절합니다. –
나는 UITabBarController를 전혀 사용하지 않고 UIViewController를 UITabBar와 함께 사용하는 것을 선호합니다. – mk12