我试图给相机视图一个圆形来拍摄图像。圆应该是 200 宽和 200 高,当它打开时,用户必须能够与背景视图交互。到目前为止,我所做的只是:
- (IBAction)useCameraPhoto:(id)sender
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePicker =
[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =
UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = [NSArray arrayWithObjects:
(NSString *) kUTTypeImage,
nil];
imagePicker.allowsEditing = YES;
[self presentViewController:imagePicker
animated:YES completion:nil];
newMedia = YES;
}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];
}
}
这段代码展示了一个视图控制器,用户可以从中进行拍摄,但它不是圆形的。
我想做类似 imagePicker.allowsEditing.frame = CGRectMake (30, 100, 200, 200); 但这仍然不会给它圆角。此外,它下面的视图即使可见,也不会响应触摸。有任何想法吗?
编辑:
我试过这个。它给出了圆角,但背景仍然是黑色
imagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
imagePicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:imagePicker animated:YES completion:nil];
imagePicker.view.layer.cornerRadius = 100; // this value vary as per your desire
imagePicker.view.clipsToBounds = YES;
imagePicker.view.frame = CGRectMake(40,40, 200, 200);