UIScrollView 缩放从 UIImageView 移除变换 [英] UIScrollView zoom removes transform from UIImageView

查看:33
本文介绍了UIScrollView 缩放从 UIImageView 移除变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,允许用户通过按下按钮在屏幕上旋转图像.

I have the following code that allows a user to rotate an image on screen by pressing a button.

self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, rotationAmount);

此图像位于 UIScrollView 内,用户可以通过该视图放大照片.问题是当用户缩放时,变换会被重置.我可以存储变换的值,然后在缩放后重新应用它,但图像看起来好像在旋转版本和非旋转版本之间跳跃.

This image is sitting inside of a UIScrollView which enables a user to zoom in on the photo. The problem is that when a user zooms the transform is reset. I can store the value of the transform and then re apply it after zooming but the image appears as though it is bouncing between the rotated version and non rotated version.

有没有办法在缩放过程中保持变换?

Is there a way to maintain the transform during zoom?

这是滚动视图的代码

self.scrollView.minimumZoomScale=1.0;
self.scrollView.maximumZoomScale=6.0;
self.scrollView.contentSize=CGSizeMake(screenHeight, screenWidth-toolBarHeight);
self.scrollView.delegate=self;
[_scrollView setContentMode:UIViewContentModeScaleAspectFit];
[_scrollView sizeToFit];
[_scrollView setContentSize:CGSizeMake(_imageView.frame.size.width, _imageView.frame.size.height)];

推荐答案

我早就应该提出这个问题,而不是仅仅评论 Matt 的回答,抱歉.

I should've put this up a long time ago rather than just comment on Matt's answer, sorry.

正如 Matt 所暗示的,UIScrollView 通过操纵其内容视图的变换属性来发挥它的魔力(缩放和平移).如果您尝试在同一个 UIView 上操作 transform 属性,那么您将破坏 scrollView 的努力.您需要在视图层次结构中的不同级别应用旋转,请考虑旋转 scrollView 本身.最好的

As Matt alludes, UIScrollView works it's magic (zoom & pan) by manipulating the transform property of its content view. If you try to manipulate the transform property on the same UIView then you will be sabotaging the scrollView's efforts. You need to apply your rotation at a different level in the view hierarchy, consider rotating the scrollView itself. Best

这篇关于UIScrollView 缩放从 UIImageView 移除变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆