I'm trying to display a large and high quality zoomable image using CATiledLayer and UIScrollView. My code is based on the iOS Large image downsizing sample code.
The hierarchy of my UIScrollView is like that :
- UIScrollView
- UIImageView : that represents the first thumbnail of the large image
- Old TiledView
- TiledView
I want that the image into the scrollview become movable.
I tried what I found on this StackOverflow topic and it works. But after the first zoom on the image, it becomes impossible to move the image. I don't know why ?
Here is my code :
-(id)initWithFrame:(CGRect)frame image:(UIImage*)_image {
if((self = [super initWithFrame:frame])) {
// Set up the UIScrollView
// Piece of code
self.canCancelContentTouches = NO;
UIPanGestureRecognizer* panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panGesture setMinimumNumberOfTouches:1];
[panGesture setMaximumNumberOfTouches:1];
[panGesture setDelegate:self];
[frontTiledView addGestureRecognizer:panGesture];
frontTiledView.exclusiveTouch = YES;
UIPanGestureRecognizer* panGesture2 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panGesture2 setMinimumNumberOfTouches:1];
[panGesture2 setMaximumNumberOfTouches:1];
[panGesture2 setDelegate:self];
[backgroundImageView addGestureRecognizer:panGesture2];
backgroundImageView.exclusiveTouch = YES;
UIPanGestureRecognizer* panGesture3 = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panGesture3 setMinimumNumberOfTouches:1];
[panGesture3 setMaximumNumberOfTouches:1];
[panGesture3 setDelegate:self];
[backTiledView addGestureRecognizer:panGesture3];
backTiledView.exclusiveTouch = YES;
}
return self;
}
- (void)move:(UIGestureRecognizer*)sender {
CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:frontTiledView];
if([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {
positionDeplacement = frontTiledView.center;
}
translatedPoint = CGPointMake(positionDeplacement.x+translatedPoint.x, positionDeplacement.y+translatedPoint.y);
frontTiledView.center = translatedPoint;
backTiledView.center = translatedPoint;
backgroundImageView.center = translatedPoint;
}
Thanks.
UIPanGestureRecognizer
in aUIScrollView
if that's what you are doing. The scroll view has its own delegate methods for panning. – Daniel Zhang