我有一个按钮,它将以编程方式创建一个UIImageView,其中包含他们从照片库中选择的每张照片的图像。它将照片放在视图上,你可以移动它,什么不可以。
当用户按住图像时,它会在iPad上显示UIPopOverController。用户点击按钮编辑当前正在触摸的图像。
我遇到的问题是我无法重新访问UIImageView.image以将图像更改为刚编辑完的图像。
以下是一些代码示例。
// This figures out what imageView was tapped
- (void)handleEditTapped:(UITapGestureRecognizer *)recognizer {
editImage = (UIImageView*)recognizer.view;
if(UIGestureRecognizerStateBegan == recognizer.state) {
// Called on start of gesture, do work son!
popoverEditor = [[UIPopoverController alloc] initWithContentViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"popupEditor"]];
[popoverEditor presentPopoverFromRect:editImage.bounds inView:editImage permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
然后,我将使用popupEditor View上的按钮弹出我的editorController:
- (IBAction)effectsEditorButton:(id)sender {
// This part I've been fooling around with to save the image and re-load it to try and get it to work but it loads successfully to the editor but will not save back to uiimageview.image
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *imageData = [defaults dataForKey:@"image"];
UIImage *loadedImage = [UIImage imageWithData:imageData];
myEditorController *editorController = [[myEditorController alloc] initWithImage:loadedImage];
[editorController setDelegate:self];
popoverEditor = [[UIPopoverController alloc] initWithContentViewController:editorController];
[popoverEditor presentPopoverFromRect:self.effectsButtonImage.bounds inView:self.effectsButtonImage permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
然后在用户编辑完照片后调用它:
- (void)photoEditor:(myEditorController *)editor finishedWithImage:(UIImage *)finishedImage
{
// NSLog(@"TAG: %i",editImage.tag); Tried tags but wouldn't hold the .tag value to re reference it. Would always result in 0 after I set the tag to 10 on handleEditTapped
editImage.image = finishedImage;
[self.popoverEditor dismissPopoverAnimated:YES];
}
我无法弄清楚如何重新访问UIImageView.image。我尝试过标签和nsuserdefaults,但无济于事!
任何帮助将不胜感激!!谢谢!
答案 0 :(得分:0)
这个问题非常关注应用程序逻辑,并且在很大程度上取决于您如何设计对象,而不是在框架,iOS或objc上。在这方面,有一些关于如何调整应用程序设计以解决此问题的建议。没有足够的信息来提供完整的答案,但希望这会有所帮助。