Using my little knowledge of iOS trying to test Zoom function on a ImageView, i dont want to use scrollView so tried with UIPinchGestureRecognisor.
it may be my fault on testing it on simulator, i am trying to test using alt key and mouse movements, as i read on many of posts and searched on google.
here is CODE i have tried.
in .h file
@interface DetailView : UIViewController <UIGestureRecognizerDelegate>
in implementation file
in ViewdidLoad
UIPinchGestureRecognizer *pinchImage = [[UIPinchGestureRecognizer alloc] initWithTarget:self
action:@selector(makePinch:)];
pinchImage.delegate = self;
[self.myLrgImageView addGestureRecognizer:pinchImage];
Tried with these Selector Methods one by one
1.
-(void)makePinch:(UIPinchGestureRecognizer*)sender
{
static CGRect initialBounds;
if (sender.state == UIGestureRecognizerStateBegan)
{
initialBounds = myLrgImageView.bounds;
}
CGFloat factor = [(UIPinchGestureRecognizer *)sender scale];
CGAffineTransform zt = CGAffineTransformScale(CGAffineTransformIdentity, factor, factor);
myLrgImageView.bounds = CGRectApplyAffineTransform(initialBounds, zt);
}
2.
CGFloat lastScale;
CGPoint lastPoint;
- (void)makePinch:(UIPinchGestureRecognizer *)sender
{
if (sender.state == UIGestureRecognizerStateBegan) {
lastScale = 1.0;
lastPoint = [sender locationInView:myLrgImageView];
}
// Scale
CGFloat scale = 1.0 - (lastScale - sender.scale);
[myLrgImageView.layer setAffineTransform:
CGAffineTransformScale([myLrgImageView.layer affineTransform],
scale,
scale)];
lastScale = sender.scale;
// Translate
CGPoint point = [sender locationInView:myLrgImageView];
[myLrgImageView.layer setAffineTransform:
CGAffineTransformTranslate([myLrgImageView.layer affineTransform],
point.x - lastPoint.x,
point.y - lastPoint.y)];
lastPoint = [sender locationInView:myLrgImageView];
}
set break point on selector method but compilor never enters in this method.
may be these piece of codes working perfectly, and i am wrong in using the simulator in right way for two finger test,
holding option key and mouse left click & moving mouse didn't give me any success.
holding command + option key with mouse left click and moving mouse didn't give me any success.
help me about this issue.
Use self.myLrgImageView.userInteractionEnabled = YES; You can test PinchGesture on Simulator using (command + alt) keys and mouse.