gpt4 book ai didi

ios - CoreAnimation 旋转一个对象并同时改变它的位置

转载 作者:行者123 更新时间:2023-11-28 18:40:58 26 4
gpt4 key购买 nike

我想做的是左右旋转 View ,同时上下移动它的位置。

这是我的代码:

CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-12.0));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(12.0));

flyingGuy.transform = leftWobble; // starting point

[UIView beginAnimations:@"wobble" context:flyingGuy];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationDuration:1.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];

flyingGuy.transform = rightWobble;
CGRect frame = flyingGuy.frame;
frame.origin.y += 10;
[flyingGuy setFrame:frame];

[UIView commitAnimations];


- (void)wobbleEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([finished boolValue]) {
UIView* item = (UIView *)context;
item.transform = CGAffineTransformIdentity;
}
}

使用当前代码, View 大小会随着向上或向下移动而改变。有什么建议吗?

最佳答案

不要在设置转换后设置或获取框架!

来自文档:

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


你应该怎么做

更改 View 的 center 属性。无论如何你只是在改变位置,当你应用了转换时这是安全的。

关于ios - CoreAnimation 旋转一个对象并同时改变它的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10983091/

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