0
votes

I got some problem when i'm zooming, when i zoom the next UIImageView goes above the UIImageView i m zooming in.

I load my UIImageView in a subclass of a UIScrollView that i call in controller. The load function and Scroll function work perfectly.

The first problem is that when I zoom in the next UIImageView goes above the one that i m zooming in.

So i tried to put every UIImageView in a UIView that i put into the ScrollView but it does the same things...

The 2nd problem that I have is that when i zoom in, my scroll doesn't work anymore.

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    scroll.pagingEnabled=YES;

    NSInteger numberOfViews = 6;
    for (int i = 0; i < numberOfViews; i++) {
        CGFloat xOrigin = i * self.view.frame.size.width;
        image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i]]];

        image.frame=CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height);

      [scroll addSubview:image];
   }

   scroll.maximumZoomScale=6.0;
   scroll.minimumZoomScale=0.5;
   scroll.delegate=self;
   scroll.clipsToBounds=YES;


   scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);

   [self.view addSubview:scroll];
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return image;
}

I know that there are questions similar to this but nothing helps my cause.Any suggested changes in my code to make it correct is more than appreciated.

3
check out zooming and paging here: raywenderlich.com/10518/… - NeverHopeless
@NeverHopeless I already did thanks for your google search.I am not using Paging,I am using a single UIImageView - vishnuvarthan
Is not using paging then why this scroll.pagingEnabled = YES; ? Also, how do you zoom when you have min/max zoom scales equal to 1.0 ? - NeverHopeless
@NeverHopeless. Sorry i meant to say page control. zoom scale values i was testing with different values. I edited the code. - vishnuvarthan
@NeverHopeless do you know the answer ?? - vishnuvarthan

3 Answers

0
votes
-(UIView *) viewForZoomingInScrollView : (UIScrollView *)scrollView
{
     return _image3;
     _image3.userInteractionEnabled = YES;
     _image3.multipleTouchEnabled = YES;
}


-(void)  tapfucntion : (UIGestureRecognizer *)  guesture
{ 
    if  (self.scroll.zoomScale >_ scroll.minimumZoomScale )
        [self.scroll setZoomScale:_scroll.minimumZoomScale animated:YES];
    else
        [self.scroll setZoomScale:2.0 animated:YES];
}
0
votes

in ViewDidLoad

- (void)viewDidLoad
{
   _tap = [ [ UITapGestureRecognizer  alloc ]  initWithTarget : self action :  @selector( tapfucntion: ) ] ;

   _tap.numberOfTapsRequired=2;

   [self.scroll addGestureRecognizer: _tap];
}
0
votes

Better to use CollectionView to overcome that problem. Using Storyboard to create easily.

  1. Create collectionview with customCell inside a cell add scrollview and imageview.

  2. Set ScrollViewDelegate to CollectionViewCell.

  3. Add this delegate method in collectionviewCellClass.

    - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return [scrollView viewWithTag:imageView]; }