UIImagerPicker“移动和缩放”不起作用

时间:2012-01-27 00:03:59

标签: iphone ios5 camera uiimagepickercontroller

我正在使用图像选择器拍摄照片,然后转到编辑屏幕。当程序到达编辑屏幕时,尽管它在底部显示“移动和缩放”,但它不允许我移动或缩放图像。控件似乎已经死了。我将叠加视图移动到屏幕顶部,以确保它不会干扰控件。这是我设置图像选择器的代码:

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType

{
    self.imagePickerController.sourceType = sourceType;

    if (sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        self.imagePickerController.showsCameraControls = YES;
        if (self.imagePickerController.allowsEditing==FALSE) 
        {
            self.imagePickerController.allowsEditing = TRUE;
        }
    [self.imagePickerController.cameraOverlayView addSubview:self.view];
    }

    if (sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum)
    {
    }
}

我需要做些什么才能使移动和缩放控件生效?

3 个答案:

答案 0 :(得分:3)

即使我的叠加视图设计为320宽x 44高,imagePicker cameraOverlayView默认为320 x 480,覆盖图像视图“移动和缩放”拖动和捏合手势。我调整了cameraOverlayView的大小,“Move and Scale”开始工作。以下是添加cameraOverlayView的代码(叠加层是self.view):

    CGRect overlayRect = self.view.frame;
    [self.imagePickerController.cameraOverlayView setFrame:overlayRect];
    [self.imagePickerController.cameraOverlayView addSubview:self.view];

答案 1 :(得分:1)

你应该更像这样创建/呈现UIImagePicker视图:

if (![UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerSourceTypeCamera])
{
    //no camera available, notify the user then exit before crashing the app
    return;
}

//display picker control (no release, assume ARC)
UIImagePickerController * uiimage_picker = [[UIImagePickerController alloc] init];
[uiimage_picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[uiimage_picker setAllowsEditing:YES];

[uiimage_picker setDelegate: self];    
[self presentModalViewController:uiimage_picker animated:YES];

您不必使用模态控制器,您可以将其作为子视图,但这是显示它的默认方式。

答案 2 :(得分:0)

初始化时

UIImagePickerController  *imagepicker=[[UIImagePickerController alloc]init];
            imagepicker.delegate=self;
            imagepicker.allowsEditing = YES;
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
                imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
            }

在委托方法中,您可以使用键UIImagePickerControllerEditedImage获取已编辑的图像

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{


    UIImage *img=[info objectForKey:UIImagePickerControllerEditedImage];
}