ZaB*_*anc 6 iphone animation quartz-graphics
这完全是iPhone的庸俗.我正在开发一个库,但已将我的问题缩小到非常简单的代码.这段代码的作用是创建一个50x50的视图,应用几度的旋转变换,然后将帧向下移动几次.结果是50x50视图现在看起来更大.
这是代码:
// 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;
Run Code Online (Sandbox Code Playgroud)
那么,到底发生了什么?现在,如果我通过应用平移变换来移动视图,它就可以正常工作.但这不是我想做的事情,无论如何这都应该有效.
有任何想法吗?
Ole*_*ann 15
从UIView文档:
如果还设置了transform属性,请改用bounds和center属性; 否则,动画更改框架属性不会正确反映视图的实际位置.
警告:如果transform属性不是identity变换,则此属性的值未定义,因此应忽略.
换句话说,frame
当a transform
设置时,我会对属性保持警惕.
归档时间: |
|
查看次数: |
3670 次 |
最近记录: |