我有一个UISlider
,我正在尝试使用动画在UISlider
的轨道上添加动态子视图。在添加每个子视图之前,我需要1秒的时间延迟。我怎样才能做到这一点?
答案 0 :(得分:1)
这是如何实现目标的基本设置:
@interface ViewController () {
NSTimer *_timer;
CGRect sliderFrame;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.slider.minimumValue = 0.0f;
self.slider.maximumValue = 100.0f;
sliderFrame = self.slider.frame;
_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(addLabel:) userInfo:nil repeats:YES];
[_timer fire];
}
- (void) addLabel:(NSTimer*) timer {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(sliderFrame.origin.x + self.slider.value/100 * self.slider.frame.size.width, sliderFrame.origin.y - 10, 20, 20)];
label.text = @"1";
[self.view addSubview:label];
}
@end
答案 1 :(得分:0)
假设您正在使用动画块,那么在您的块中您可以使用setAnimationDelay。例如;
[UIView animateWithDuration:5.0 animations:
^{
[UIView setAnimationDelay:1.0];
...
} completion:^(BOOL finished){
...
}];
这会在开始前延迟1秒进行5秒动画。
答案 2 :(得分:0)
您可以使用action方法将valueChangeEvent连接起来。
您可以在该方法中放置一个动画块,并在启动动画作为延迟参数之前将秒数传递给等待。
[UIView animateWithDuration:(NSTimeInterval) delay:(NSTimeInterval) options:(UIViewAnimationOptions) animations:^(void)animations completion:^(BOOL finished)completion]
然后你可以改变你想要的任何动画添加视图。