简体   繁体   中英

zoom in with multiple UIImageView in UIScrollView

I've got some problem when i'm zooming, when i zoom the next UIImageView goes above the UIImageView im 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 im 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.

- (UIView*)viewForZoomingInScrollView:(UIScrollView *)scrollView {
// Return the view that you want to zoom
NSLog(@"viewForZoomingInScrollView - current : %d",self.scrollPageControl.currentPage);
return [[[[self.productImageScrollView subviews]objectAtIndex:0] subviews]objectAtIndex:self.scrollPageControl.currentPage];
//return [[self.productImageScrollView subviews] objectAtIndex:0];
//return [self.productImageScrollView getSubViewsByPage:[NSNumber numberWithInteger:[self.scrollPageControl currentPage]]];

The first return return a UIImageView of the UIView The second return the UIView the third return the UIImageView when i don't use the UIView.

I saw a lot of similar problem but nothing i tried helped me ... So I m calling you ! Ty ask me if i'm not clear.

try creating an UIView * (maybe call it contentView) and put all of your UIImageView's as subviews to that contentView

then, on the

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

Are you returning that view in the method? that's the key part ...

The scroll view will only scale the view you return in the viewForZooming, so if you are returning one of your images, the rest will not scale. I assume you are adding them in order, so when the zoomed one enlarges, the next one will stay still and therefore be on top of the current one

Try adding all the images to a view and then return that same view in the viewForZoomingInScrollView:

This is the function that determine what object will zoom:

func viewForZooming(in scrollView: UIScrollView) -> UIView?{
    return scrollImageView
}

then you can add what you want to that object as a subview and it will zoom to:

scrollImageView.addSubview(teritorysImages)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM