我有一個UISlider
,我正嘗試在動畫UISlider
的軌道上動態添加子視圖。在添加每個子視圖之前,我需要1秒的時間延遲。我怎樣才能做到這一點?在UISlider上添加延時子視圖?
0
A
回答
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
0
假設你使用的是動畫塊,那麼,你的塊中,你可以使用setAnimationDelay。例如;
[UIView animateWithDuration:5.0 animations:
^{
[UIView setAnimationDelay:1.0];
...
} completion:^(BOOL finished){
...
}];
這將做一個5秒的動畫,延遲1秒後纔開始。
0
您可以使用操作方法來掛接valueChangeEvent。
您可以在該方法中放置一個動畫塊,並在開始動畫之前傳遞等待的秒數作爲延遲參數。
[UIView animateWithDuration:(NSTimeInterval) delay:(NSTimeInterval) options:(UIViewAnimationOptions) animations:^(void)animations completion:^(BOOL finished)completion]
然後你可以改變添加任何動畫你需要的視圖。
相關問題
- 1. 添加子視圖,延遲?
- 2. 延遲添加視圖
- 3. IOS在viewDidLoad上添加子視圖
- 4. 在子視圖中讀取UISlider值?
- 5. 添加子視圖到主視圖在tableViewController添加子視圖到表視圖,而不是在swift視圖
- 6. 如何在UISlider上添加觀察者
- 7. 在滾動視圖上高效添加多個子視圖
- 8. 在當前視圖上添加視圖
- 9. 添加延遲期間添加視圖在Android
- 10. 添加子視圖是否也添加該視圖的子視圖?
- 11. 添加子視圖後視圖呈現
- 12. UITableViewCell子類 - 在IBAction上添加子視圖
- 13. ember.js添加子視圖
- 14. 泄漏添加子視圖
- 15. 向UITableViewCell添加子視圖
- 16. 添加子視圖到UITableCellView
- 17. WKWebView添加到子視圖
- 18. 添加動畫子視圖
- 19. 添加一個子視圖
- 20. 向Splashscreen添加子視圖
- 21. 的UITableView添加子視圖
- 22. 在視圖背面繪製視圖(添加爲子視圖)
- 23. 在另一個子視圖中添加子視圖
- 24. UIButton在添加到子視圖時未收到觸摸,但在添加到主視圖時未收到觸摸
- 25. 子視圖呈現延遲
- 26. 延遲顯示子視圖
- 27. gestureRecognizer無法在添加的子視圖
- 28. 在awakeFromNib中添加子視圖
- 29. 在中心添加子視圖 - iPad
- 30. 在UINavigationController中添加子視圖