我需要添加到我的視圖n個子視圖的時間間隔,並設置它們的角半徑也與時間間隔。 問題是,他們都一起調用自我沒有時間間隔(立即)。如何以時間間隔動畫調用n個子視圖
我試過Timer.sheduledTimer和GCD但我沒有結果。 也許我做錯了什麼 請講一些知道該怎麼做
func addSubviews(count : Int, completeon : (_ view : UIView)->()) {
view.subviews.forEach({ $0.removeFromSuperview() })
for i in 1...count {
let inscribedView = UIView()
inscribedView.translatesAutoresizingMaskIntoConstraints = false
let sizeConstant = ((self.screenWidth/2)/self.viewsCount)
self.view.addSubview(inscribedView)
//setup constraints
self.view.addConstraint(NSLayoutConstraint.init(item: inscribedView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1, constant: CGFloat(count == viewsCount ? statusBarHeight + sizeConstant * i : sizeConstant * i)))
self.view.addConstraint(NSLayoutConstraint.init(item: inscribedView, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1, constant: -CGFloat(sizeConstant * i)))
self.view.addConstraint(NSLayoutConstraint.init(item: inscribedView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1, constant: -(CGFloat)(count == self.viewsCount ? self.tabBarHeight + sizeConstant * i : sizeConstant * i)))
self.view.addConstraint(NSLayoutConstraint.init(item: inscribedView, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1, constant: CGFloat(sizeConstant * i)))
inscribedView.backgroundColor = RandomFlatColor()
}
completeon(view)
}
override func viewDidLoad() {
super.viewDidLoad()
self.becomeFirstResponder()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewWillLayoutSubviews()
}
override func viewWillLayoutSubviews() {
addSubviews(count: viewsCount) { view in
for subview in view.subviews {
subview.addCornerRadiusAnimation(from: 0, to: 20, duration: 0.3)
}
}
}
viewWillAppear中後,你爲什麼打電話viewWillLayoutSubviews? – Tj3n
我有一個標籤欄,我需要我重繪子視圖,如果我通過標籤 –
你搞亂了VC委託方法,我不認爲它是一個好主意,只是用'view.layoutIfNeeded()'調用你的動畫,而不是調用請再次委託方法 – Tj3n