Вам необходимо создать подкласс класса 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