我正在创建一个只有横向的应用,它使用图像选择器控件。
通过该网站,我发现苹果出于某种原因只允许肖像。如果它意味着用户可以从库中选择一张照片,我可以将它翻到这一部分的肖像。 下面是我的代码,它给出了横向模式的错误。我如何解决这个问题,说它可以翻转成肖像。感谢
-(IBAction)takePhoto{
takePicker = [[UIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];
}
-(IBAction)chooseExisiting{
choosePicker = [[UIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];
}
答案 0 :(得分:0)
为什么会出现错误?为什么不以肖像呈现图像选择器?人们足够聪明,可以旋转他们的设备。或者您可以编写自己的风景图像选择器,或者使用几种可用的开源图像选择器之一。
答案 1 :(得分:0)
您不必在纵向模式下使用UIImagePickerController。 只需将其子类化为以横向模式打开:
@interface NonRotatingUIImagePickerController : UIImagePickerController
@end
@implementation NonRotatingUIImagePickerController
- (BOOL)shouldAutorotate
{
return NO;
}
@end
之后,您可以将该代码用于该类。
-(IBAction)takePhoto {
takePicker = [[NonRotatingUIImagePickerController alloc]init];
takePicker.delegate = self;
[takePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:takePicker animated:YES completion:NULL];
}
-(IBAction)chooseExisiting{
choosePicker = [[NonRotatingUIImagePickerController alloc]init];
choosePicker.delegate = self;
[choosePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:choosePicker animated:YES completion:NULL];
}