我的目标是让用户从 a 中捕获屏幕截图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;
}