我以这种方式将 UIImagePickerController 添加到我的视图中:
- (IBAction)TakeCameraShot:(id)sender{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
// Given by default your orientation is in landscaperight already
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
/* picker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
picker.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;*/
[self presentViewController:picker animated:YES completion:nil];
/* picker.view.layer.cornerRadius = 150;
picker.view.clipsToBounds = YES;
picker.view.frame = CGRectMake(12, 60, 296, 290);*/
}else{
NSLog(@"Camera is not available");
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Important message" message:@"Unfortunately the camera is not available on your device." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert1 show];
}
}
我正在尝试使用此代码防止它被旋转到横向
// Given by default your orientation is in landscaperight already
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
提供的堆栈溢出的答案还说它只有在 UIviewController 已经设置为仅纵向时才有效,所以这是我从一般应用程序设置(您选择 ipad、iphone 或通用)中所做的。但这不起作用。