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