我设法获得一个动画进度条,在10秒的时间内滚动视图的顶部。但是我需要扭转它。
以下是完整代码:
public enum BarPosition {
case Top
case TopStatus
case Bottom
}
class HBRViewController: UIViewController {
let kStandardBarHeight: CGFloat = 5
var progressBarPosition: BarPosition = BarPosition.Top
var progressBarColor: UIColor = UIColor.blueColor()
private var isProgressing: Bool = false
private var progressBar: UIView = UIView(frame: CGRectZero)
func startLoading() {
if !isProgressing {
self.progressBar.frame = CGRectMake(0, self.position(), 0, kStandardBarHeight)
self.progressBar.backgroundColor = self.progressBarColor
if self.progressBar.superview != self.view {
self.view.addSubview(self.progressBar)
}
self.isProgressing = true
let barWidth: CGFloat = self.view.frame.size.width * 1
UIView.animateWithDuration(10, animations: { () -> Void in
self.progressBar.frame = CGRectMake(0, self.position(), barWidth, self.kStandardBarHeight)
})
}
}
func finishLoading() {
if isProgressing {
let projectileFrame = self.progressBar.layer.presentationLayer()!.frame
self.progressBar.layer.removeAllAnimations()
self.progressBar.frame = projectileFrame
UIView.animateWithDuration(0.3, animations: { () -> Void in
self.progressBar.frame = CGRectMake(0, self.position(), self.view.frame.size.width, self.kStandardBarHeight)
}) { (Bool) -> Void in
self.hideProgressBar()
}
}
}
private func hideProgressBar() {
UIView.animateWithDuration(0.2, animations: { () -> Void in
switch self.progressBarPosition {
case .Top, .TopStatus:
self.progressBar.frame.size.height = 0
case .Bottom:
self.progressBar.transform = CGAffineTransformMakeTranslation(0, CGRectGetHeight(self.progressBar.frame))
}
}) { (Bool) -> Void in
self.progressBar.removeFromSuperview()
self.progressBar.transform = CGAffineTransformIdentity
self.isProgressing = false
}
}
func position() -> CGFloat {
switch self.progressBarPosition {
case .TopStatus:
if (self.navigationController != nil) {
return CGRectGetMaxY(self.navigationController!.navigationBar.frame)
} else {
return CGRectGetMaxY(UIApplication.sharedApplication().statusBarFrame)
}
case .Top:
if (self.navigationController != nil) {
return CGRectGetMaxY(self.navigationController!.navigationBar.frame)
} else {
return 0.0 as CGFloat
}
case .Bottom:
return self.view.frame.size.height - kStandardBarHeight
}
}
}
有人可以告诉我如何让屏幕显示在屏幕的整个宽度上然后在10秒内收缩?