gpt4 book ai didi

ios - CGAffineTransform 旋转后改变框架?

转载 作者:行者123 更新时间:2023-11-28 18:59:32 25 4
gpt4 key购买 nike

我在某个角度添加了 UIView。现在在运行时我想将该 View 向上移动(比如 20 像素)。

开始

 dragView = [[DragbleView alloc] initWithFrame:CGRectMake(10, 200, 200, 90)];
dragView.transform = CGAffineTransformMakeRotation (-0.663247);

在运行时

  NSLog(@"Before : %@",NSStringFromCGRect(dragView.frame));
[dragView setCenter:CGPointMake(dragView.frame.origin.x, dragView.center.y+20)];
NSLog(@"After : %@",NSStringFromCGRect(dragView.frame));

控制台 O/p

Before : {{3.4947295778412979, 147.97225037436704}, {213.0105408443174, 194.05549925126593}}
After : {{-103.0105408443174, 167.97225037436704}, {213.0105408443174, 194.05549925126593}}

如您所见,它去了错误的地方。如何放置在 20 px 以上

最佳答案

如果您阅读有关 UIView 框架属性的文档,他们会说:

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

因此,一旦更改了 View 的变换,就无法再更改框架。它不再起作用。

您应该使用 View 的 center 属性,正如@GaryRiches 在他的回答中所建议的那样。

关于ios - CGAffineTransform 旋转后改变框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27530289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com