내 응용 프로그램에서 나는 탭바와 탐색 모음을 모두 가지고 있습니다. rootview 컨트롤러 tabbar 및 tabbar 4 탐색 컨트롤러가 있습니다.일부보기 컨트롤러의 방향 고정
몇 가지 뷰 컨트롤러를 세로로 만 만들고 싶습니다. 그것은 일반적인 질문 일지 모르지만 나는 충분히 노력했지만 그것을 해결할 수 없었다.
일부보기 컨트롤러의 세로 방향을 만드는 방법은 무엇입니까?
내 응용 프로그램에서 나는 탭바와 탐색 모음을 모두 가지고 있습니다. rootview 컨트롤러 tabbar 및 tabbar 4 탐색 컨트롤러가 있습니다.일부보기 컨트롤러의 방향 고정
몇 가지 뷰 컨트롤러를 세로로 만 만들고 싶습니다. 그것은 일반적인 질문 일지 모르지만 나는 충분히 노력했지만 그것을 해결할 수 없었다.
일부보기 컨트롤러의 세로 방향을 만드는 방법은 무엇입니까?
누군가가 똑같은 문제에 직면하면 도움을 얻을 수 있도록이 문제를 해결하고 답변했습니다.
shouldAutorotate, supportedInterfaceOrientations, preferredInterfaceOrientationForPresentation
위의 방법은 navigationcontroller의 tabbarcontroller 안에 있으면 viewcontroller가 호출되지 않습니다. 이러한 메서드가 tabbarcontroller 또는 navigation 컨트롤러 내부에 선언되어 있으면 호출됩니다. 내 경우에는 viewcontrollers 내비게이션 컨트롤러 안에 있었고 탐색 컨트롤러 tabbarcontroller 안에 있습니다.
이 문제를 해결하기 위해 FixedOrientationTab 클래스를 만들고 UITabBarController의 하위 클래스이며 OrientationEnabledNavigation 클래스 인 UINavigationController의 하위 클래스입니다. 그런 다음 FixedOrientationTab 및 OrientationEnabledNavigation 내부에 shouldAutorotate, supportedInterfaceOrientations, preferredInterfaceOrientationForPresentation
메서드를 구현했습니다.
OrientationEnabledNavigation.h
#import <UIKit/UIKit.h>
@interface OrientationEnabledNavigation : UINavigationController
@end
OrientationEnabledNavigation.m
#import "OrientationEnabledNavigation.h"
@interface OrientationEnabledNavigation()
@end
@implementation OrientationEnabledNavigation
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
// return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.topViewController preferredInterfaceOrientationForPresentation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
FixedOrientationTab.h
#import <UIKit/UIKit.h>
@interface FixedOrientationTab : UITabBarController
@end
,745,
FixedOrientationTab.m
#import "FixedOrientationTab.h"
@interface FixedOrientationTab()
@end
@implementation FixedOrientationTab
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
// return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
그런 다음 프로젝트에 네비게이션 컨트롤러를 사용 OrientationEnabledNavigation 및 TabBar의의 FixedOrientationTab을 위해 사용하려는 경우. 그 후 shouldAutorotate, supportedInterfaceOrientations, preferredInterfaceOrientationForPresentation
메서드를 viewcontroller 내부에 구현하면 호출됩니다.
희망이 도움이 .. ..