8

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];
                 }];

2番目のものをアニメートするだけです...

4

2 に答える 2

14

2番目のアニメーションを最初のアニメーションの完了ブロックに配置して、アニメーションをチェーンする必要があります。

-(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
        }];
    }];
}
于 2012-12-15T17:51:23.733 に答える
2

rdelmarの答えのためのSwift2.2バージョン

@IBOutlet weak var slider: UISlider!

func animateSlider(sender: AnyObject){
    UIView.animateWithDuration(2, animations:  {() in
        self.slider.setValue(0.75, animated: true)
        }, completion:{(Bool)  in
            UIView.animateWithDuration(2, animations: {() in
                self.slider.setValue(0.25, animated: true)
            })
    })
}

関数を呼び出すには、パラメーターでUISliderを渡します

animateSlider(self.slider)
于 2016-04-26T13:35:00.230 に答える