UIImagePicker相机内存警告停止将图像设置为UIImageView

时间:2012-03-18 04:23:10

标签: ios cocoa-touch memory-management uiimagepickercontroller

我有一个显示UIImagePicker的模态,允许用户拍摄照片然后放入UIImageView。

每隔一段时间我就会得到一个内存警告'收到内存警告'并且UIImageView没有被分配。该应用程序相当简单,并没有使用大量内存,而且似乎很多时候这与ImagePicker作为一个单独的进程有关。这仅在使用相机时发生,并且大约发生五次。

有一个lot of talk about this online,大多数答案都说'适当地处理警告';但我不确定这意味着什么 - 我只是希望拍摄的照片出现在ImageView中!似乎在我可以在UIImagePicker委托中做任何事情之前发生。

我可以做些什么来缓解这种情况?

这是didFinishPickingImage委托:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo {
    //set background for image select button, put image reference somewhere to copy image to documents folder and insert into modular's sentence object.
    //ImagePicker.jpg needs it's border set to 1px black.

    NSLog(@"imagePickerController: selectedimage: %@", selectedImage);

    imageViewBehindPhotoBigButton.clipsToBounds = YES;
    [imageViewBehindPhotoBigButton.layer setBorderColor: [[UIColor blackColor] CGColor]];
    [imageViewBehindPhotoBigButton.layer setBorderWidth: 1.0];
    [imageViewBehindPhotoBigButton setBackgroundColor:[UIColor whiteColor]];

    [imageViewBehindPhotoBigButton setContentMode: UIViewContentModeScaleAspectFill];
    imageViewBehindPhotoBigButton.image = selectedImage;

    imageViewBehindPhotoBigButton.hidden = NO;
    [choosePhotoBigButton setBackgroundImage:nil forState:UIControlStateNormal];

    choosePhotoBarImage.hidden = NO; 
    choosePhotoText.hidden = NO;

    addButton.enabled = YES;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {      
        //because iPad uses a pop up - we don't want to dismiss modals here!
        [imagePopupController dismissPopoverAnimated:YES];

    }else{
        [self dismissModalViewControllerAnimated:YES];    
    }



}

1 个答案:

答案 0 :(得分:5)

答案是在从UIImagePickerController缩放/处理图像时实现线程。我使用here进行了非常好的讨论。