0
A
回答
1
- 設置視圖層次方式如下:
Basicly你有containerView
和progressView
。您將操作progress view
的width constraint
。
所以,容器視圖有一個修復高度,並約束一切到超視圖。進度視圖有0個前導,頂部和底部約束,並且現在可以將寬度設置爲0。
ProgressView
幀和約束:
ContainerView
幀和constaints:
現在是時候在您的viewController
中進行編碼了。
#import "ViewController.h"
@interface ViewController()
// Create IBOutlet for the progressView's width constraint
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *progressViewWidthContraint;
// Declare a timer
@property (nonatomic, strong) NSTimer *progressTimer;
@property (nonatomic, assign) CGFloat progressPerSecond;
@end
@implementation ViewController
// Progress time can be changed on demand
NSInteger kProgressTime = 60;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// Lets setup how much should the progress be increased by a second
self.progressPerSecond = self.view.frame.size.width/kProgressTime;
// Lets start showing the progress
[self startOrResetTimer];
}
- (void)startOrResetTimer {
// Just in case invalidate the timer before we would set it up
[self.progressTimer invalidate];
// Set the progressView's constant to its initial phase
self.progressViewWidthContraint.constant = 0;
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
// Create the timer
self.progressTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateProgress) userInfo:nil repeats:true];
}
- (void)updateProgress {
// If the progress has reached the end of the screen, do not increase the constraint's constant
if (self.progressViewWidthContraint.constant == self.view.frame.size.width) {
return;
}
// Increase the constant by the previously calculated progress per second
self.progressViewWidthContraint.constant += self.progressPerSecond;
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}
// Hook this method to your reset button on the interface builder, and any time you press the button, it will reset the timer and the progressbar
- (IBAction)didTapResetTimerButton:(UIButton *)sender {
[self startOrResetTimer];
}
@end
希望這有助於!
相關問題
- 1. 動畫在IOS圖形基於定時器和進度條
- 2. Android有沒有進度條/定時器?
- 3. 進度條和計時器
- 4. ios中的自定義進度條
- 5. ios自定義進度條設計
- 6. iOS - 進度條值從php
- 7. ios進度條在uitableview中
- 8. 加載進度條IOS
- 9. 進度條計時器暫停時鐘
- 10. 綁定進度條
- 11. 進度條或計時器合併
- 12. 使進度條與計時器同步
- 13. 具有計時器的進度條
- 14. 倒數計時器與進度條
- 15. 從(System.Timer)定時器事件訪問進度條
- 16. 的setInterval定時器需要動畫的進度條
- 17. VB進度條在定時器間隔上移動?
- 18. 定時器配置jFrame並填充進度條
- 19. 進度條定時器只刷新頁面刷新
- 20. 服務器端 - 進度條
- 21. MP3播放器進度條
- 22. iOS 8視頻進度條不可見
- 23. 在iOS中創建動畫進度條
- 24. 更新iOS 5中的進度條
- 25. 亞馬遜s3 ios下載進度條
- 26. 動畫進度條適用於iOS
- 27. iOS的進度條不更新
- 28. iOS Swift 3 WKWebView進度條未顯示
- 29. iOS無狀態/無價值進度條?
- 30. 不確定進度條?
簽出'UIProgressView',雖然它可能不是你想要的。否則,你有沒有看過動畫UIView的寬度? –
使用SubView創建自定義視圖。 subView應該是UIView。用定時器增加SubView的寬度。 – AshokPolu