【发布时间】:2018-08-07 03:51:52
【问题描述】:
我正在尝试用动画填充水平视图(如进度条之类)(因此它将从左边缘填充到右侧)。
这是我拥有的,但它不起作用
override init(frame: CGRect) {
super.init(frame: frame)
let outlineView = UIView()
outlineView.layer.borderColor = UIColor.black.cgColor
outlineView.layer.borderWidth = 1
endorsementViews.append(outlineView)
addSubview(outlineView)
// custom UIView anchor extension
outlineView.anchor(topAnchor, left: leftAnchor, bottom: nil, right: rightAnchor, topConstant: 12, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 75)
let fillView = UIView()
fillView.backgroundColor = .orange
fillView.alpha = 0
fillViews.append(fillView)
outlineView.addSubview(fillView)
// custom UIView anchor extension
fillView.anchor(outlineView.topAnchor, left: outlineView.leftAnchor, bottom: outlineView.bottomAnchor, right: nil, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 195, heightConstant: 0)
}
override func layoutSubviews() {
super.layoutSubviews()
for index in 0...2 {
let fillWidth = 75
UIView.animate(withDuration: 3.5) {
self.fillViews[index].frame.size.width = fillWidth
}
}
}
【问题讨论】:
-
“必须”使用
UIView还是可以使用CALayer或其他方法 -
我认为你不能只设置宽度。尝试设置整个框架。另外,因为您使用的是锚点。使用它们制作动画。
标签: swift animation uiview uiviewanimation