9

正如标题所说,我需要在使用UIImagePickerController. 我想.png在相机上添加非常简单的文件(如空框),但我不知道该怎么做。

我已经检查了这个网页上的大部分教程,但大部分都不懂。对我来说似乎很难,将一个简单.png的文件添加到相机覆盖应该比这更容易。

(IBAction) getPhoto:(id) sender {
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    } else {

    }

    label1.text =@"PHOTO ACTION";

    [self presentModalViewController:picker animated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

我应该在哪里实现我的覆盖代码?我应该使用哪些课程,我该怎么做?

4

1 回答 1

15

有一个UIImagePickerController叫做的属性cameraOverlayView。它是UIView*一个picker.

好的,这是代码(我没有测试过)

(IBAction) getPhoto:(id) sender 
{
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    // creating overlayView
    UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.frame];
    // letting png transparency be
    overlayView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"yourimagename.png"]];
    [overlayView.layer setOpaque:NO];
    overlayView.opaque = NO;

    picker.showsCameraControls = NO;
    picker.cameraOverlayView = overlayView;

    if((UIButton *) sender == choosePhotoBtn) 
    {
         if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
         {
             [picker setSourceType:UIImagePickerControllerSourceTypeCamera];
         } else {
             //do something if the device has no camera or if the camera is disabled in settings (it cannot be assumed that the camera is available/not broken)
         }
    } else {

    }

    label1.text =@"PHOTO ACTION";

    [self presentModalViewController:picker animated:YES];
}

当然,您可以使用一些自定义UIView*子类而不是创建标准UIView* overlayView,但其他一切都将保持不变。

于 2012-09-24T20:27:12.103 回答