UIViewController
의 하위 클래스를 만들어야합니다. 그리고이 하위 클래스에서 인터페이스 방향 관련 변경 사항을 적용합니다. 하위 클래스를 사용하여 방향을 고정하고자하는보기 컨트롤러를 확장하십시오. 이에 대한 예를 들어 보겠습니다.
보기 컨트롤러의 가로 방향 만 표시하는 클래스를 만듭니다.
LandscapeViewController
은 오리엔테이션을 처리해야하는 UIViewController
의 하위 클래스입니다.
LandscapeViewController.h :
#import <UIKit/UIKit.h>
@interface LandscapeViewController : UIViewController
@end
LandscapeViewController.m :
#import "LandscapeViewController.h"
@interface LandscapeViewController()
@end
@implementation LandscapeViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL)shouldAutorotate {
return YES;
}
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
}
else {
return NO;
}
}
@end
이 서브 클래스 이상 사용하여 뷰 컨트롤러를 확장합니다. 예를 들어
:
#import "LandscapeViewController.h"
@interface SampleViewController : LandscapeViewController
@end
이 당신의 마음을 확인, 당신은 현재 또는 푸시 사용하고 있습니까? – matt