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

时间:2012-05-12 03:52:19

标签: iphone objective-c ios frame bounds

我有一个全屏UIScrollView来显示我的图像,它使用来自Apple示例代码的PhotoScroller.app中的一些代码。我对在带有旋转的scrollView和convertPoint中的imageView的边界感到困惑。任何帮助将不胜感激!

PS。有关更多详细信息,请参阅Center of bounds

NSLog in call willRotateToInterfaceOrientation:duration:

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 in call 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;

旋转前的imageview帧原点(NSLog in willRotateToInterfaceOrientation:duration)是(0,0),旋转后(willAnimateRotationToInterfaceOrientation:duration :)中的NSLog,我认为它应该是(80,-120)。但它是(80.000008,0.000017);

3 个答案:

答案 0 :(得分:1)

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

要获取imageView的实际中心,您可以使用:

imageView.center

答案 1 :(得分:1)

请访问此链接。

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

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

我认为它对你有帮助。

谢谢

此致 Keyur Bhalodiya

答案 2 :(得分:1)

frame属性始终根据UIView的boundscentertransform属性返回计算的值。

根据Apple的UIView documentation

  

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

问题是您在旋转动画开始时正在阅读frame属性,这意味着您的观点将具有非身份transform值,使其成为frame价值观毫无意义。

您可以根据other question

中的代码记录这样的转换值
NSLog(@"imageScrollView transform %@", NSStringFromCGAffineTransform(self.transform));

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

这将显示旋转时的transform属性。如果你不熟悉身份变换,那就是[1, 0, 0, 1, 0, 0]

换句话说,frame属性为您提供意外值的原因是您的视图已应用transform,导致frame属性无意义。

目前尚不清楚您实际想要实现的目标,但同一Apple文档中的其他说明可能会有所帮助:

  

如果transform属性包含非标识转换,则frame属性的值未定义且不应修改。在这种情况下,您可以使用center属性重新定位视图,并使用bounds属性调整大小。