Note that there are some explanatory texts on larger screens.

plurals
  1. POImage size resets to original after performing pich using UIPichGestureRecognizer in iphone
    primarykey
    data
    text
    <p>I have one view controller in which I have added UIScrollView &amp; UIImageView programatically. I have added UIPichGestureRecognizer to the UIImageView. My UIImageView is added to UIScrollView as a subview. </p> <p>My problem is when I try to pinch the image , it zoom in. But when I release the touches from screen it again come to its default size. I can not find the error in code. Please help me. Below is my code</p> <pre><code> - (void)createUserInterface { scrollViewForImage = [[UIScrollView alloc]initWithFrame:CGRectMake(20.0f, 60.0f, 280.0f, 200.0f)]; scrollViewForImage.userInteractionEnabled = YES; scrollViewForImage.multipleTouchEnabled = YES; scrollViewForImage.backgroundColor = [UIColor redColor]; scrollViewForImage.autoresizesSubviews = YES; scrollViewForImage.maximumZoomScale = 1; scrollViewForImage.minimumZoomScale = .50; scrollViewForImage.clipsToBounds = YES; scrollViewForImage.delegate = self; scrollViewForImage.bouncesZoom = YES; scrollViewForImage.contentMode = UIViewContentModeScaleToFill; [self.contentView addSubview:scrollViewForImage]; imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 280.0f, 200.0f)]; [imageView setBackgroundColor:[UIColor clearColor]]; imageView.userInteractionEnabled = YES; imageView.multipleTouchEnabled = YES; UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)]; [pinchRecognizer setDelegate:self]; [imageView addGestureRecognizer:pinchRecognizer]; //[self.contentView addSubview:imageView]; [self.scrollViewForImage addSubview:imageView]; scrollViewForImage.contentSize = CGSizeMake(imageView.frame.size.width , imageView.frame.size.height); } -(UIView *) viewForZoomingInScrollView:(UIScrollView *)inScroll { return imageView; } -(void)pinch:(id)sender { [self.view bringSubviewToFront:[(UIPinchGestureRecognizer*)sender view]]; if([(UIPinchGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) { lastScale = 1.0; return; } CGFloat scale = 1.0 - (lastScale - [(UIPinchGestureRecognizer*)sender scale]); CGAffineTransform currentTransform = [(UIPinchGestureRecognizer*)sender view].transform; CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, scale, scale); [[(UIPinchGestureRecognizer*)sender view] setTransform:newTransform]; lastScale = [(UIPinchGestureRecognizer*)sender scale]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload