作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法在不使用 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/
我是一名优秀的程序员,十分优秀!