【发布时间】:2010-11-20 12:55:47
【问题描述】:
我在UIScrollView 中有一个UIImageView,而contentOffset 属性有一些问题。根据 Apple 的参考,这被定义为:
contentOffset:内容视图的原点与滚动视图的原点的偏移点。
例如,如果图像在屏幕的左上角,如下图,那么 contentOffset 将为 (0,0):
_________
|IMG |
|IMG |
| |
| |
| |
| |
---------
对于设备旋转,我有以下设置:
scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight);
imageView.contentMode = UIViewContentModeCenter;
scrollView.contentMode = UIViewContentModeCenter;
这将使一切围绕屏幕中心旋转。 旋转屏幕后,屏幕将如下所示:
______________
| IMG |
| IMG |
| |
--------------
我的问题是,如果我现在读到 contentOffset,它仍然是 (0,0)。 (如果我在横向模式下移动 UIImage,contentOffset 的值会更新,但它是根据错误的原点计算的。)
有没有办法计算 UIImage 相对于屏幕左上角的坐标。 contentOffset 似乎只在屏幕处于视图的初始方向时才返回此值。
我曾尝试阅读self.view.transform 和scrollView.transform,但它们始终是身份。
【问题讨论】: