gpt4 book ai didi

ios - 无尽的赛跑者 imageview 动画(无 SpriteKit)

转载 作者:行者123 更新时间:2023-11-29 12:02:24 26 4
gpt4 key购买 nike

有没有办法在不使用 CABasicAnimation 的情况下从右到左为 UIImageView 设置动画?我遇到了麻烦,我想找到另一种方法来做到这一点。

“地面”图像的尺寸为 1200(宽)x 33(高),我想将它从右向左移动,以模拟无限重复的无休止运行者。

如果没有 CALayer/CABasicAnimation,我如何实现它?

谢谢!

最佳答案

UIView 上有很多方法可以实现任何动画,尤其是移动 View 。

您可以像这样移动您的 imageView:

[UIView animateWithDuration:10
animations:^{

yourImageView.frame = frame_you_need;
}
completion:^(BOOL finished){

//start from the very beginning
//set initial frame to the image view and run the
// animation again
}];

所以你需要两个 ImageView 。设置它们的起始位置,在两者上运行动画,完成动画后再次重复动画。就是这样

更新

我决定自己实现这个功能。这是我的动画功能的样子:

- (void)runView:(UIView *)aView withStartPosition:(CGPoint)startPosition
{
aView.center = startPosition;

[UIView animateWithDuration:3
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{

CGPoint newPosition = CGPointMake(aView.center.x + aView.frame.size.width, aView.center.y);
aView.center = newPosition;
}
completion:^(BOOL finished){

[self runView:aView withStartPosition:startPosition];

}];
}

演示此功能的项目位于此处:Github

关于ios - 无尽的赛跑者 imageview 动画(无 SpriteKit),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36359784/

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