Here's the idea of what I'm trying to accomplish, as if this were layers
(TOP) - Annotation Pin (30 x 30px) This is a UIImageView. - UIViewImage with a picture - UIScrollView
The idea is that you can push a button in the view a new pin image shows up on the center of the screen, but you want to reposition that pin to where it makes sense to show an area of the picture. Also, additional pins will then be placed on the center of the screen if you push the pin button again, leaving the first pin where you moved it to already.
I can add the UIPanGestureRecognizer to a small app with just a UIViewImage, but once this view is inside a view and inside a uiscrollview, it doesn't work.
Here's my declaration file, being only a delegate for the UIScrollView:
#import <UIKit/UIKit.h>
@interface ImageAnnotationVC : UIViewController <UIScrollViewDelegate>
{
UIPanGestureRecognizer *panRecognizer;
}
Here's how my scrollView is getting initialized:
- (void)viewDidLoad
{
[super viewDidLoad];
imageView_image.image = originalImage;
scrollView.contentSize = originalImage.size;
scrollView.delegate = self;
scrollView.minimumZoomScale = 1.0;
scrollView.maximumZoomScale = 100.0;
}
Here's how the pin gets created and brought up to the screen:
- (IBAction)button_addAnnotation:(id)sender
{
UIImageView *annotationImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"[email protected]"]];
[annotationImage setCenter:CGPointMake(imageView_image.bounds.size.width / 2, imageView_image.bounds.size.height / 2)];
panRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];
[annotationImage addGestureRecognizer:panRecognizer];
[imageView_image addSubview:annotationImage];
}
And here's the target method:
- (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
NSLog("In handlePan");
}
The problem is that handlePan never gets called. Any ideas? Thank you!
UIImageView
s userInteractionEnabled? – Lyndsey Scott