带有旋转的scrollView中imageView的边界 [英] Bounds of an imageView in a scrollView with rotation
问题描述
我有一个全屏UIScrollView来显示我的图像,它使用了来自Apple示例代码的PhotoScroller.app中的一些代码.我对带有旋转的scrollView和convertPoint中的imageView的边界有点困惑.任何帮助将不胜感激!
I have a full screen UIScrollView to display my image, which employ some codes from PhotoScroller.app from apple sample code. I am little confused on the bounds of a imageView in a scrollView with rotation, and the convertPoint. Any help will be appreciated!
ps.有关更多详细代码,请访问边界中心
ps. For more detail codes please find in Center of bounds
NSLog调用将RotateToInterfaceOrientation:持续时间:
2012-05-12 11:35:45.666 imageScrollView frame X and Y are 0.000000 and 0.000000
2012-05-12 11:35:45.672 imageScrollView frame Width and Height are 320.000000 and 480.000000
2012-05-12 11:35:45.677 imageScrollView bounds origin X and Y are 0.000000 and 0.000000
2012-05-12 11:35:45.682 imageScrollView bounds Width and Height are 320.000000 and 480.000000
2012-05-12 11:35:45.686 imageView frame origin X and Y are 0.000005 and 0.374437
2012-05-12 11:35:45.689 imageView frame size Width and Height are 320.000000 and 479.251129
2012-05-12 11:35:45.693 imageView bounds origin X and Y are 0.000000 and 0.000000
2012-05-12 11:35:45.697 imageView bounds size Width and Height are 641.000000 and 959.999939
2012-05-12 11:35:45.701 boundsCenter X and Y are 160.000000 and 240.000000
2012-05-12 11:35:45.705 convertPoint origin X and Y are 320.500000 and 479.999969
NSLog调用willAnimateRotationToInterfaceOrientation:duration:
2012-05-12 11:36:05.975 imageScrollView frame X and Y are 0.000000 and 0.000000
2012-05-12 11:36:05.978 imageScrollView frame Width and Height are 480.000000 and 320.000000
2012-05-12 11:36:05.983 imageScrollView bounds origin X and Y are 0.000000 and 0.000000
2012-05-12 11:36:05.987 imageScrollView bounds Width and Height are 480.000000 and 320.000000
2012-05-12 11:36:05.990 imageView frame origin X and Y are 80.000008 and 0.000017
//I am confused here. Why is the X is 80.000008, and Y is 0.000017, but not (80, -120)?
2012-05-12 11:36:05.994 imageView frame size Width and Height are 320.000000 and 479.251099
2012-05-12 11:36:06.002 imageView bounds origin X and Y are 0.000000 and 0.000000
2012-05-12 11:36:06.006 imageView bounds size Width and Height are 641.000000 and 959.999878
2012-05-12 11:36:06.009 boundsCenter X and Y are 240.000000 and 160.000000
2012-05-12 11:36:06.014 convertPoint origin X and Y are 320.500000 and 320.499969
关于自动调整大小的配置:
actionSheetCoverView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageScrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
旋转之前(NSLog在willRotateToInterfaceOrientation:duration中)的图像视图原点为(0,0),旋转之后(NSLog在willAnimateRotationToInterfaceOrientation:duration :)中的图像视图原点为(80,-120).但这是(80.000008,0.000017);
推荐答案
frame
属性始终基于bounds
,center
和transform
属性返回计算出的值UIView.
The frame
property always returns a calculated value based on the bounds
, center
, and transform
properties of a UIView.
按照Apple的
如果 If the 问题在于,您在旋转动画开始时正在读取 The problem is that you're reading the 您可以根据其他问题中的代码,像这样记录转换值: You can log the transform values like so, based on the code from your other question: 这将在旋转时向您显示transform属性.如果您不熟悉身份转换,则为 This will show you the transform property at the time of rotation. If you're not familiar with the Identity Transform, it's 换句话说, In other words, the reason the 尚不清楚您实际上要实现什么目的,但是来自同一Apple文档的其他说明可能会有所帮助: It's not clear what you're actually trying to achieve, but this other note from the same Apple documentation may be of help: 如果 If the 这篇关于带有旋转的scrollView中imageView的边界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!transform
属性不是恒等变换,则frame
属性的值未定义,因此应忽略.
transform
property is not the identity transform, the value of the frame
property is undefined and therefore should be ignored.frame
属性,这意味着您的视图将具有非同一性transform
值,从而使它们的frame
值变得毫无意义.frame
property at the start of a rotation animation, which means your views will have a non-identity transform
value, making their frame
values meaningless.NSLog(@"imageScrollView transform %@", NSStringFromCGAffineTransform(self.transform));
NSLog(@"imageView transform %@", NSStringFromCGAffineTransform(imageView.transform));
[1, 0, 0, 1, 0, 0]
. [1, 0, 0, 1, 0, 0]
. frame
属性为您提供意外值的原因是因为您的视图已应用transform
,从而使frame
属性变得毫无意义.frame
property is giving you unexpected values is because your view has a transform
applied to it, rendering the frame
property meaningless.
transform
属性包含一个非同一变换,则frame
属性的值是不确定的,不应修改.在这种情况下,您可以使用center
属性重新定位视图,而使用bounds
属性调整大小.
transform
property contains a non-identity transform, the value of the frame
property is undefined and should not be modified. In that case, you can reposition the view using the center
property and adjust the size using the bounds
property instead.