ios – Animate UISlider顺利进行动画制作

我想为UISlider设置动画,例如0.25到0.75然后回来.这应该向用户显示要做什么.

我试过这个:

[self incrementCounter:[NSNumber numberWithInt:0]];


-(void) incrementCounter:(NSNumber *)i {
    [Slider setValue:[i floatValue]/1000];
    [self performSelector:@selector(incrementCounter:) withObject:[NSNumber numberWithInt:i.intValue+1] afterDelay:0.001];
}

但那不是那么顺利……我可以使用转换吗?

[Slider setValue:1 animated:YES];

快要…

[UIView animateWithDuration:2.0
                 animations:^{
                     [Slider setValue:0.2];
                 }];
[UIView animateWithDuration:2.0
                 animations:^{
                     [Slider setValue:0.5];
                 }];

只是动画第二个……

解决方法

您需要通过将第二个动画放在第一个动画的完成块中来链接动画:
-(IBAction)animateSlider:(id)sender {

    [UIView animateWithDuration:2 animations:^{
        [self.slider setValue:.75];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2 animations:^{
            [self.slider setValue:0.25];//or `[self.slider setValue:(.75)-(.5*finished)];` if you want to be safe
        }];
    }];
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...