带有旋转的scrollView中的imageView的边界

我有一个全屏的UIScrollView来显示我的图像,它采用从苹果示例代码从PhotoScroller.app一些代码。 我有点困惑的旋转scrollView和convertPoint的imageView的界限。 任何帮助将不胜感激!

PS。 有关更多详细信息,请在边界中心find

NSLog调用willRotateToInterfaceOrientation:持续时间:

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:持续时间:

 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 

关于自动调整configuration:

 actionSheetCoverView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; imageScrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; 

在rotate(NSLog在willRotateToInterfaceOrientation:持续时间)之前的imageview框架起源是(0,0),在旋转(NSLog在willAnimateRotationToInterfaceOrientation:持续时间:)后,我认为它应该是(80,-120)。 但是(80.000008,0.000017);

frame属性总是返回一个基于UIView的boundscentertransform属性的计算值。

根据苹果的UIView文档 :

如果transform属性不是标识转换, frame属性的值是未定义的,因此应该忽略。

问题在于,在旋转animation开始的时候你正在读取frame属性,这意味着你的视图将会有一个非同一的transform值,这使得它们的frame值没有意义。

你可以像这样logging变换值,根据你的另一个问题的代码:

 NSLog(@"imageScrollView transform %@", NSStringFromCGAffineTransform(self.transform)); NSLog(@"imageView transform %@", NSStringFromCGAffineTransform(imageView.transform)); 

这将显示旋转时的transform属性。 如果您对Identity变换不熟悉,则为[1, 0, 0, 1, 0, 0]

换句话说, frame属性给你意想不到的值的原因是因为你的视图有一个transform应用到它,渲染frame属性是毫无意义的。

目前还不清楚你实际上想要达到什么效果,但是来自苹果公司相同文档的其他说明可能有帮助:

如果transform属性包含非标识转换,那么frame属性的值是未定义的,不应该修改。 在这种情况下,您可以使用center属性重新定位视图,并使用bounds属性来resize。

正如我所解释的,当你不说出你为什么感到困惑或者你想要做什么的时候,很难帮助你。

为了得到imageView的实际中心,你可以使用这个:

 imageView.center 

请访问此链接。

http://www.raywenderlich.com/9864/how-to-create-a-rotating-wheel-control-with-uikit#more-9864

您可以从那里获取示例代码和编码指南。

我认为它对你有帮助。

谢谢

问候,Keyur Bhalodiya