2 garaster garaster 于 2013.06.26 16:31 提问

ipad将图片放到UIPopoverController中

我的目标是让用户能从UIWebView抓取屏幕截图。然后将图片加载到UIPopoverController中。

UIPopoverController中用户可剪裁并保存图片。

目前我实现了UIImage屏幕截图。然后UIPopoverController弹出,但是不能保存图片,好像是由于这句代码: imagePicker sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
应该怎么修改呢?

全部代码:

-(UIImage*)captureScreen:(UIView*) viewToCapture
{    
    UIGraphicsBeginImageContext(viewToCapture.bounds.size);
    [viewToCapture.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    imageView.image = viewImage;
    [imageView setHidden:NO];
    // this removes current view ie photoLibary
    [self dismissViewControllerAnimated:YES completion:NULL];

    // this checks that a popover is not already in view
    if ([popoverController isPopoverVisible]) 
   {
        // if yes - remove
        [popoverController dismissPopoverAnimated:YES];
   } 
   else 
   {     
        // create an imagePicker
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.allowsEditing = YES;
        // create an PopoverController
        popoverController = [[UIPopoverController alloc]
                             initWithContentViewController:imagePicker];
        popoverController.delegate = self;
        UIView *popView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 500, 500)];
        [self.view addSubview:popView];

        [popoverController presentPopoverFromRect:CGRectMake(100,200, 565, 545)
                                           inView:self.view
                         permittedArrowDirections:0
                                         animated:YES];
    }
    return viewImage;
}

1个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.17 00:42
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!