好吧,这让我在过去几天疯了。我希望这是一个简单的解决方案。我正在尝试访问我的UIImageView.image,以便稍后可以替换它。
这里只需要代码:
// .h
@property (strong,nonatomic) UIImage *doneImage;
@property (strong,nonatomic) UIImageView *editImage;
// .m
@synthesize doneImage;
@synthesize editImage;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, widthOfImage, heightOfImage)];
imgView.image = originalImage;
imgView.userInteractionEnabled = YES;
[self.mainView addSubview:imgView];
// I add gestures
longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1;
longPress.numberOfTouchesRequired = 1;
[imgView addGestureRecognizer:longPress];
}
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
editImage = (UIImageView*)recognizer.view; // I declare what editImage is and now have access to what imageView is being interacted with.
doneImage = editImage.image; // I then get the image of that for later use.
if(UIGestureRecognizerStateBegan == recognizer.state) {
popoverEditor = [[UIPopoverController alloc] initWithContentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"popupEditor"]];
[popoverEditor presentPopoverFromRect:editImage.bounds inView:editImage permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (IBAction)effectsEditorButton:(id)sender {
// editImage is my imageView
if (editImage == nil) {
NSLog(@"imageView was nil wtf");
} else {
[self performSelector:@selector(editImageWithEffects:)];
}
}
任何帮助都会得到非常赞赏。谢谢!
答案 0 :(得分:0)
您是否遗漏了代码?根据你在这里的内容,editImage将永远为null,因为它没有在任何地方声明(也许是Interface Builder中我们看不到的东西?)。
您需要一种从弹出窗口链接回视图控制器的方法。流行的方法是从弹出控制器返回时使用完成块,或者将“主”VC设置为弹出窗口中的弱属性。