滚动视图中的图像视图的边界与旋转[英] Bounds of an imageView in a scrollView with rotation

本文是小编为大家收集整理的关于滚动视图中的图像视图的边界与旋转的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有一个全屏幕UISC​​rollView来显示我的图像,该图像采用了photoscroller.app中的一些代码.我对滚动视图中旋转和转换点的图像视图的界限并不感到困惑.任何帮助将不胜感激!

ps.有关更多详细信息代码,请在范围中心

中心

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 in Call willanimatimatotation tointerfaceorientation:持续时间:

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框架原点(willrotatetointerfaceorientation:持续时间)为(0,0),旋转(旋转(nslog in willanimatimatimationtation tointerfaceorientation::) purs :),我认为应该是(80, -120).但这是(80.000008,0.000017);

推荐答案

frame属性始终基于bounds,center和transform属性返回 值.

的属性.

按照苹果的 uiview文档:

如果transform属性不是身份变换,则frame属性的值不确定,因此应被忽略.

问题在于,您在旋转动画开始时读取frame属性,这意味着您的视图将具有非身份transform值,使其frame值毫无意义.

您可以根据

这将在旋转时向您显示变换属性.如果您不熟悉身份变换,那是[1, 0, 0, 1, 0, 0].

换句话说,frame属性给您出乎意料的值的原因是因为您的视图对其进行了transform,因此frame属性毫无意义.

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

如果transform属性包含一个非身份变换,则frame属性的值是未定义的,不应修改.在这种情况下,您可以使用center属性重新定位视图,并使用bounds属性调整大小.

其他推荐答案

正如我所解释的那样,当您不说自己为什么感到困惑或尝试做什么时,很难为您提供帮助.

要获取ImageView的实际中心,您可以使用以下方式:

imageView.center

本文地址:https://www.itbaoku.cn/post/2091193.html

问题描述

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. For more detail codes please find in 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

About the autoresizing configuration:

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

The imageview frame origin before rotate (NSLog in willRotateToInterfaceOrientation:duration) is (0, 0) , after rotate (NSLog in the willAnimateRotationToInterfaceOrientation:duration:), i think it should be (80, -120). But it is (80.000008, 0.000017);

推荐答案

The frame property always returns a calculated value based on the bounds, center, and transform properties of a UIView.

As per Apple's UIView documentation:

If the transform property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.

The problem is that you're reading the 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.

You can log the transform values like so, based on the code from your other question:

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

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

This will show you the transform property at the time of rotation. If you're not familiar with the Identity Transform, it's [1, 0, 0, 1, 0, 0].

In other words, the reason the frame property is giving you unexpected values is because your view has a transform applied to it, rendering the frame property meaningless.

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 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.

其他推荐答案

As I explained, it is hard to help you out when you don't say why you are confused or what you are attempting to do.

To get the actual center of the imageView, you can use this:

imageView.center