gpt4 book ai didi

iphone - 使用变换旋转,然后更改框架原点, View 会扩展?

转载 作者:行者123 更新时间:2023-12-03 18:41:53 26 4
gpt4 key购买 nike

这就是 iPhone 的困境。我正在开发一个库,但已将我的问题缩小到非常简单的代码。此代码的作用是创建一个 50x50 View ,应用几度的旋转变换,然后将帧向下移动几次。结果是 50x50 View 现在看起来更大了。

代码如下:

// a simple 50x50 view
UIView *redThing = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
redThing.backgroundColor = [UIColor redColor];

[self.view addSubview:redThing];

// rotate a small amount (as long as it's not 90 or 180, etc.)
redThing.transform = CGAffineTransformRotate(redThing.transform, 0.1234);

// move the view down 2 pixels
CGRect newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height);
redThing.frame = newFrame;

// move the view down another 2 pixels
newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height);
redThing.frame = newFrame;

// move the view down another 2 pixels
newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height);
redThing.frame = newFrame;

// move the view down another 2 pixels
newFrame = CGRectMake(redThing.frame.origin.x, redThing.frame.origin.y + 2, redThing.frame.size.width, redThing.frame.size.height);
redThing.frame = newFrame;

那么,这到底是怎么回事?现在,如果我通过应用平移变换来移动 View ,它就可以正常工作。但这不是我想要做的,无论如何这应该有效。

有什么想法吗?

最佳答案

来自 UIView 文档:

If the transform property is also set, use the bounds and center properties instead; otherwise, animating changes to the frame property does not correctly reflect the actual location of the view.

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

换句话说,当设置 transform 时,我会对 frame 属性保持警惕。

关于iphone - 使用变换旋转,然后更改框架原点, View 会扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2752256/

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