效果圖:

33.gif
廢話不多說直接上代碼:
class ViewController: UIViewController {
var mView = UIView(frame: CGRect(x: 100, y: 200, width: 100, height: 100))
override func viewDidLoad() {
super.viewDidLoad()
mView.backgroundColor = UIColor.red
self.view.addSubview(mView)
}
/**
在點擊屏幕方法中模擬這個效果
*/
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
UIView.animate(withDuration: 0.8, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: UIViewAnimationOptions.curveEaseInOut, animations: {[unowned self] in
self.mView.transform = CGAffineTransform(scaleX: 1.5, y: 1.5)
self.mView.center.y -= 10
}) { [unowned self](true) in
// Tips: 下面這兩行代碼是為了恢復(fù)原狀 但是膜拜單車中地圖覆蓋物的效果是沒有恢復(fù)原狀的 因為重新加載地圖覆蓋物會移除掉舊的覆蓋物 所以不必擔(dān)心覆蓋物會一直往上移或者說覆蓋物只會變大一次之后第二次就沒有效果 ^_^!
self.mView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
self.mView.center.y += 10
}
}
}