2013-08-28 20 views
2

我想給圓形的相機視圖拍攝圖像。圓應該是200寬和200高,並且當它打開時,用戶必須仍然能夠與背景視圖交互。所有我現在已經到管理的是:相機控制器的自定義形狀IOS

- (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]; 
} 

} 

此代碼是從呈現,用戶可以採取了一槍一viewcontrller,但它不具有圓形。

我想過要做點像 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); 

回答

1

而不是做一個模式彈出,你可以使用AVFoundation直接添加攝像頭的支持。蘋果開發者網站上有一個不錯的iOS camera demo already available for free

然後你就可以在預覽圖像連接到您的UIViewController一個UIImageView和做同樣的事情,其層,以獲得所需的效果:

imageView.view.layer.cornerRadius = 100; // this value vary as per your desire 
imageView.view.clipsToBounds = YES; 
imageView.view.frame = CGRectMake(40,40, 200, 200);