好吧,最近几天这让我发疯了。我希望这是一个简单的解决方法。我正在尝试访问我的 UIImageView.image,以便稍后替换它。
这里只有所需的代码:
每次用户单击其库中的照片时,我首先创建一个 imageView。
// .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];
}
这会弹出一个带有 4 个按钮的菜单。然后我有一个 IBAction 试图启动编辑部分。
- (IBAction)effectsEditorButton:(id)sender {
// editImage is my imageView
if (editImage == nil) {
NSLog(@"imageView was nil wtf");
} else {
[self performSelector:@selector(editImageWithEffects:)];
}
}
我的图像视图始终为零。我需要以某种方式获得对它的引用。我已经尝试过标签,但一旦达到这一点,我似乎无法让它们保持其价值。
任何帮助将不胜感激。谢谢!