У меня есть UIImagePickerController, и я бы хотел, чтобы его ориентация сохранялась в портретном режиме в любое время. Само приложение установлено в портретном режиме, но UIImagePickerController меняет ориентацию. Я создал пользовательский UIImagePickerController с кодом:UIImagePickerController вращается, когда устройство повернуто iOS 7
#import "ViewControllerImage.h"
@interface ViewControllerImage()
- (BOOL)shouldAutorotate;
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
- (NSUInteger)supportedInterfaceOrientations;
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@end
@implementation ViewControllerImage
- (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.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
И я представляю его таким образом:
ViewControllerImage *picker = [[ViewControllerImage alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
код не работает контроллер еще вращается. Зачем?
когда я добавить код, который я получаю ошибку Поддерживаемые ориентации не имеет общей ориентации с приложением, и shouldAutorotate является возвращение YES – Alessandro
@Alessandro http://stackoverflow.com/questions/12540597/supported-orientations-has-no-common-orientation-with-the-application-and-shoul –
Для решения этой проблемы мне необходимо включить ландшафтный режим, что в любом случае не решило бы мою первоначальную проблему. – Alessandro