旋转 UIView 对象 x 轴
我有一个 UIView 子类对象,其初始高度为 obj.frame.size.height。
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(...)];
imageView setImage:...
//here comes rotation
我有一个变量 double newHeight (它小于 obj 的初始高度) 我需要按 x 轴旋转 obj。 旋转后 obj 的高度必须更改为 newHeight 我怎么能这么做呢?
I have a UIView subclassed object with initial height obj.frame.size.height.
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(...)];
imageView setImage:...
//here comes rotation
I have a variable double newHeight (it is less than obj's initial height)
I need to rotate obj by x axis.
after rotation obj's height must change to newHeight
How could I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 QuartzCore 转换来实现此目的。首先,如果尚未完成,您必须添加 QuartzCore 框架。现在将
导入到相应的文件中。实现 x 轴翻转并将大小调整到新高度的示例转换可能如下所示:test1
这里是需要转换的视图。这是通过首先绕 y 轴旋转半圆(以弧度表示的 PI)来实现的(这实际上是左右翻转)。然后,缩放变换使 x 和 z 保持原样,但缩放 y,以便新的高度恰好是所需的newSize
。请注意,此转换仅更改渲染。例如,如果您现在将视图的边界更改为新高度,则转换将应用于该高度,并且您将缩放新(更大/更小)对象两次。根据所需的旋转,您还可以沿 x 轴旋转以上下翻转或围绕 z 进行任意旋转,例如 CATransform3DMakeRotation(M_PI_4, 0.0, 0.0, 1.0) 顺时针旋转 45 度。还要注意转换的顺序,因为这可能会导致不良效果。
You can use QuartzCore transformations to achieve this. First of all, if not done already, you have to add the QuartzCore framework. Now import
<QuartzCore/QuartzCore.h>
in your appropriate file. An example transformation to achieve a flip on the x-Axis and resizing to a new height could look like this:test1
here is the view that needs to be transformed. This is achieved by first rotating by half a circle (PI in radians) around the y axis (this effectively flips left and right). Then a scaling transform leaves x and z as they are but scales y so that the new height will be exactly the requirednewSize
. Note that this transform only changes the rendering. If you for example now changed thebounds
of the view to the new height, the transformation would be applied to that and you would scale the new (bigger/smaller) object twice.Depending on the needed rotation you could also rotate along the x axis to flip up and down or do arbitrary rotations around z, e.g. CATransform3DMakeRotation(M_PI_4, 0.0, 0.0, 1.0) to rotate 45 degrees clockwise. Also beware of the order of transformations as this can result in undesirable effects.