방향 변경이 필요하지만 tabbarviewcontroller의 여러 견해 중 하나에 대해서만
-
20-09-2019 - |
문제
내 앱에는 5 개의 탭이있는 UitabbarController가 있습니다. 다섯 번째 탭에서만 방향을 회전해야했습니다. UitabbarController를 서브 클래스하여 5 개를 모두 조경으로 회전 할 수있었습니다.
@implementation TabBarControllerRotate
-(BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationPortrait);
}
@끝
if(tbc == nil){
//tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; ////// new //////
....
tbc.viewControllers =
[NSArray arrayWithObjects:viewController1, viewController2, viewController3
,viewController4,viewController5, nil];
이제 ViewController1-4의 회전을 끄는 것이 필요합니다. 이 ViewControllers의 4 *.M 파일에 다음 코드를 추가 하여이 작업을 수행하려고 시도했습니다.
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
R을 끝내는 방법에 대해 조언 해주세요. 읽어 주셔서 감사합니다, 마크
해결책
이 작업을 수행하는 다른 방법이 있다고 가정하지만 마침내 해결책을 얻었습니다. 방향을 변경 해야하는 유일한 TabbarController의 다섯 번째 ViewController의 제목은 "Mynotes"입니다.
SublistViewController.m 내부 TabBarControllErrotate 객체가 생성됩니다.
tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil]; tbc.viewControllers = [NSArray arrayWithObjects:viewController1 , viewController2, viewController3, viewController4, viewController5, nil tbc.delegate = self;
TabbarController 서브 클래스 UITABBARCONTROLLER 및 BOOL 속성 이름 BMynotes를 포함합니다.
SublistViewController는 UITABBARCONTROLLERDELEGATE입니다
tabbarcontroller에서보기가 변경 될 때마다 메시지가 전송됩니다. (void) tabbarcontroller : (uitabbarcontroller *) tabbarController didSelectViewController : (uiviewController *) ViewController
따라서 SublistViewController.m이 코드가 포함되어 있습니다.
#pragma mark UITabBarControllerDelegate methods - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ BOOL b = (viewController.title == @"MyNotes"); [tbc setBMyNotesTab:b]; //NSLog(@"MyNotesTab == %d", [tbc bMyNotesTab]); }
그런 다음 tabbarcontrollerrotate.m은 다음을 포함합니다.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { //NSLog(@"bMyNotesTab is: %d",self.bMyNotesTab); return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationPortrait ) && self.bMyNotesTab );
}