I have an app with a photo library viewer. In the app you can select a photo and using gestures scale and pan around the photo. I do this by changing the affine transform of the UIImageView containing the photo. The app also supports changing phone orientations. In some situations the calculation of the frame of the UIImageView on orientation change seems to be wrong. The following in general will cause the frame size to be wrongly calculated.
After this the UIImageView frame is different from what it was originally so the image looks scaled.
The autoresizing flags for the UIImageView are .flexibleWidth and .flexibleHeight. Is there something I can do to avoid this. It looks like LayoutSubviews doesn't cope very well with scaled UIViews. I tried removing the scale in viewWillLayoutSubviews() and re-applying in viewDidLayoutSubviews() but this didn't help.
Transforms do not change the bounds of your view; they are applied after autolayout is calculated. The transforms should be used for transitory things like animation and not for positioning and sizing your UI (this would for instance also give you incorrect coordinates for things like panGestureRecognizer).
I think you are better off putting your imageView into a UIScrollView than messing with the transforms. UIScrollView already handles panning and pinch to zoom so all you have to do is handle scrollViewDidZoom and adjust your constraints accordingly. here is an example .
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.