1
votes

I have a scroll view and inside the scrollview I am having a content view with few subview inside this content view. My requirement is to zoom the content view but not the subview of content view.

Can anyone faced this before, or did the same. Any help would be appreciated.

Thanks in advance.

1
Technically when parent view will zoomed child view will automatically zoomed as everything inside the scrollview , Any reason why you want to do that - Prashant Tukadiya
Do you solve your problem? - Gralex
I have the same requirement it is working for me. - Yogendra Solanki

1 Answers

2
votes

Scroll view just apply transform to contentView. This transform applied to all children in contentView. So you can apply inverted transform to children to negate parent transform.

func scrollViewDidZoom(_ scrollView: UIScrollView) {
    guard let content = viewForZooming(in: scrollView) else {
        return
    }
    let t = content.transform.inverted()
    for v in content.subviews {
        v.transform = t
    }
}