2012-12-15 8 views
7

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

をしかしそれほどスムーズではないthatsの...私はこのためにトランジションを使用することができますか?

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

ちょうど秒1をアニメーション化し

[Slider setValue:1 animated:YES]; 

断食することです... ...

答えて

14

あなたが最初の完了ブロックに秒のアニメーションを入れてチェーンにアニメーションを必要とします:

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

rdelmarためスウィフト2.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) 
関連する問題