1

Experts!! Please help me in this!!!!! In my project I am programatically creating multiple UIImageviews. I want to add Pinch gesture on each ImageView.i My code is below....

-(IBAction)addSymbols:(UIButton *)sender{
if (sender.tag ==1) {
CGRect frame =sender.frame;
[self.imgView setFrame:frame];
self.imgView.userInteractionEnabled = YES;
[imgView setImage:[sender imageForState:UIControlStateNormal]];
[self.view addSubview:imgView];
[self addGestureRecognizersToPiece:imgView];}

Like this I am adding 5 imageViews. Now code of [self addGestureRecognizersToPiece:imgView]

- (void)addGestureRecognizersToPiece:(UIView *)piece{
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)];
[piece  addGestureRecognizer:pinchGesture];

//In above add gesture on UIImageView directly its not working..
//if replace this line by [self.view addGestureRecognizer:pinchGesture]; it's working..
//but while pinch whole UIview scale

[pinchGesture setDelegate:self]; }

Another bug is UIPinchgesture is not correctly working on multiple UIImageViews individually. So please help me.. Reply me soon..

- (void) scalePiece:(UIPinchGestureRecognizer*)paramSender{ 

if (paramSender.state == UIGestureRecognizerStateEnded) { 
self.currentScale = paramSender.scale;
} 
else if (paramSender.state == UIGestureRecognizerStateBegan && self.currentScale != 0.0f){ 

paramSender.scale = self.currentScale; }
 if (paramSender.scale != NAN && paramSender.scale != 0.0){ 
[paramSender view].transform= CGAffineTransformMakeScale(paramSender.scale, paramSender.scale); 
} 

As you told me I added userInteractionEnabled = YES for each UIImageView. I mention in my code also

Nevpro
  • 33
  • 1
  • 7

2 Answers2

0

You should enable userInteractionEnabled on the UIImageViews. This is disabled by default.

If you need more help, please show us your scalePiece:code.

calimarkus
  • 9,955
  • 2
  • 28
  • 48
  • - (void) scalePiece:(UIPinchGestureRecognizer*)paramSender{ if (paramSender.state == UIGestureRecognizerStateEnded) { self.currentScale = paramSender.scale;} else if (paramSender.state == UIGestureRecognizerStateBegan && self.currentScale != 0.0f){ paramSender.scale = self.currentScale; } if (paramSender.scale != NAN && paramSender.scale != 0.0){ [paramSender view].transform= CGAffineTransformMakeScale(paramSender.scale, paramSender.scale); } As you told me I added userInteractionEnabled = YES for each UIImageView. I mention in my code also – Nevpro May 08 '12 at 11:36
  • who should read that.. put it in your post pls. And also describe your exact problem. What *doesnt* work, what behaves wrong!? – calimarkus May 08 '12 at 12:22
  • I posted my whole code above.. Now reply me if there any changes in my code – Nevpro May 08 '12 at 12:43
0

Add the imageViews as subview of ScrollView.

Then set the scrollView zoomScale of the scrollView. Also implement the delegate methods of scrollView especially the one below.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

return the imageView object you want to zoom.

refer these UIScrollView

UIScrollViewDelegate

J S Rodrigues
  • 471
  • 4
  • 8
  • Ohhk.. i'l try this one too.. I was thinking about replace my UIPinchgesture with UIscrollview and hanldle by its delegate..Thanx for reply.. – Nevpro May 08 '12 at 11:52