Tabbar-Application (Landscape-Portrait)에서 하나의 탭에서만보기를 변경 하시겠습니까?
-
19-09-2019 - |
문제
iPhone을 돌릴 때보기를 어떻게 변경할 수 있습니까 (NIB 변경). 그러나 하나의 탭에서만 발생해야합니다! 나는 그것을 시도했다 :
- (void)viewDidLoad {
LandscapeViewController *viewController = [[LandscapeViewController alloc]
initWithNibName:@"LandscapeView" bundle:nil];
self.landscapeViewController = viewController;
[viewController release];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)
name:UIDeviceOrientationDidChangeNotification object:nil]; }
- (void)orientationChanged:(NSNotification *)notification
{
[self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
{
[self presentModalViewController:self.landscapeViewController animated:YES];
isShowingLandscapeView = YES;
}
else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
{
[self dismissModalViewControllerAnimated:YES];
isShowingLandscapeView = NO;
}
}
그러나 풍경 뷰는 모든 탭에 나타납니다. (이 코드가 한 번로드 된 경우). 아이디어가 있습니까?
해결책 3
귀하의 의견을위한 탱크! 해결 방법을 찾았습니다.
//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
if (isShowingLandscapeView == NO) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
}
다른 팁
무슨 일이 일어나고 있는지 뷰 컨트롤러가 UIDeviceOrientationDidChangeNotification
회전이 변경 될 때마다 알림이 표시되는지 여부에 관계없이. 대신 내장 방법을 사용해보십시오 UIViewController
이는 회전에 응답하기위한 것입니다.
이것은 Apple의 문서 (View Controller Programming Guide)에서 나온 것입니다.
탭 막대 컨트롤러 및 회전보기
탭 바 컨트롤러는 기본적으로 인물 방향을 지원하며 모든 루트보기 컨트롤러가 그러한 방향을 지원하지 않는 한 조경 방향으로 회전하지 않습니다. 장치 방향 변경이 발생하면 탭 바 컨트롤러가 뷰 컨트롤러 배열을 쿼리합니다. 그들 중 하나가 방향을 지원하지 않으면 탭 막대 컨트롤러가 방향을 변경하지 않습니다.
따라서 탭 바 컨트롤러가 단일보기를 위해 회전하도록 설계되었는지 확신 할 수 없습니다.
제휴하지 않습니다 StackOverflow