gpt4 book ai didi

ios - 没有间隙的核心动画循环

转载 作者:行者123 更新时间:2023-11-28 22:03:25 25 4
gpt4 key购买 nike

enter image description here

假设我使用下面的代码从左到右为中央橙色“HELLO”设置动画

问: 如何为下面的自动收报机制作动画,使其看起来像 View “HELLO”在无间隙或跳跃地无休止地移动。 (把它想象成一个股票行情...)

-(void)animate:(UIView *)thisView
{
CABasicAnimation *moveView;
moveView = [CABasicAnimation animationWithKeyPath:@"position.x"];
moveView.byValue = @(self.view.frame.size.width);
moveView.duration = 3.0;
moveView.removedOnCompletion = YES;
moveView.fillMode = kCAFillModeRemoved;
moveView.autoreverses = NO;
moveView.repeatCount = 10;
[[thisView layer] addAnimation:moveView forKey:@"x"];
}

最佳答案

好的,为此您需要两个标签。此外,我将使用基于 block 的动画。自 iOS4 以来,您使用的动画方法非常古老且不鼓励使用。

无论如何...

首先你需要像这样设置你的 View ......

               | Screen width  |
| |
[ Label ]|[ Label ]|

这两个标签应该位于屏幕宽度的两倍的单个 View 中。

因此 containerView 的框架将开始类似...

CGRect containerFrame = CGRectMake(-320, 0, 640, 44);

然后你可以为动画做这个......

- (void)animateLabels
{
[UIView animateWithDuration:3.0
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
// animate the container frame to the right 320 points
containerView.frame = CGRectOffset(containerView.frame, 320, 0);
}
completion:^(BOOL finished) {
// move it back to where it started
containerView.frame = CGRectOffset(containerView.frame, -320, 0);
[self animateLabels];
}];
}

这会将两个标签滑到右边,然后快速将它们放回去并再次开始动画。它会给人一种无限行标签在屏幕上滑动的错觉。

关于ios - 没有间隙的核心动画循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24552706/

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