0

我从 developer.apple.com 下载了示例代码“使用 UIImagePickerController 选择图片并拍照”,基本上我保持原样。我已经添加了功能,如果我拍摄了一些照片,并且我再次在 imagePickerController 视图中拍摄另一张照片,它会与之前拍摄的照片重叠。还有滑块,我可以更改叠加层的不透明度,效果很好。

但是,之前拍摄的照片并未缩放以适合视图,而是只能看到原始分辨率的一部分。那么如何将 overlayImage 设置为适当的大小?我试过使用故事板/笔尖文件/以编程方式添加它,但没有成功。

@property (nonatomic, weak) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UIImageView *overlayImage;
@property (nonatomic) IBOutlet UIView *overlayView;

这是方法:

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if (self.imageView.isAnimating)
{
    [self.imageView stopAnimating];
}

if (self.capturedImages.count > 0)
{
    //[self.capturedImages removeAllObjects];
}

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = NO;

if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
    [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
    self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
    imagePickerController.cameraOverlayView = self.overlayView;
    self.overlayView = nil;
    self.overlayImage = self.imageView;
    self.overlayImage.alpha = 0.5;

    UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(60, 80, 200, 30)];
    [slider setMaximumValue:1.0];
    [slider setMinimumValue:0.0];
    [slider setValue:0.5];
    [slider addTarget:self action:@selector(sliderChanged:)  forControlEvents:UIControlEventValueChanged];

    if (self.capturedImages.count > 0)
    {
        [imagePickerController.cameraOverlayView addSubview:self.overlayImage];
        [imagePickerController.cameraOverlayView addSubview:slider];
    }
}

self.imagePickerController = imagePickerController;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}
4

2 回答 2

0

在您的代码示例中,我在任何地方都看不到设置self.imageView.frame。如果我理解正确的问题,这就是问题所在。

于 2013-09-20T16:18:07.730 回答
0

解决了!简单:

self.overlayImage.image = self.imageView.image;

代替:

self.overlayImage = self.imageView;
于 2013-09-21T07:59:07.197 回答