UIView LifeCycle
1. initWithCoder:
layerClass
setNeedsDisplay
addConstraints:
addConstraint: (can happen multiple times)
2. willMoveToSuperview:
3. invalidateIntrinsicContentSize
4. didMoveToSuperview
5. awakeFromNib
6. willMoveToWindow:
7. needsUpdateConstraints
8. didMoveToWindow
9. setNeedsLayout
10. updateConstraints
intrinsicContentSize
11. layoutSubviews (can happen multiple times)
12. drawRect:
Animate
Color Animation
UIView.animate(withDuration: 1, animations: {
self.backgroundColor = .brown
}, completion: nil)
Size Animation
UIView.animate(withDuration: 1, animations: {
self.frame.size.width += 10
self.frame.size.height += 10
}, completion: nil)
Move Animation
UIView.animate(withDuration: 1, animations: {
self.bonacinno.frame.origin.y -= 20
}, completion: nil)
Repeat Animation
UIView.animate(withDuration: 1, animations: {
self.bonacinno.backgroundColor = .brown
self.bonacinno.frame.size.width += 10
self.bonacinno.frame.size.height += 10
}) { _ in
UIView.animate(withDuration: 1, delay: 0.25, options: [.autoreverse, .repeat], animations: {
self.bonacinno.frame.origin.y -= 20
})
}