3

カメラビューに丸い形を与えて画像を撮ろうとしています。円は幅 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);
4

1 に答える 1

1

モーダル ポップアップを実行する代わりに、AVFoundationを使用してカメラ サポートを直接追加できます。Apple 開発者サイトには、すでに無料で利用できる素晴らしい iOSカメラのデモがあります。

次に、プレビュー画像を 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);
于 2013-08-28T15:57:41.727 に答える