效果图:
废话不多说直接上代码:
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: 下面这两行代码是为了恢复原状 但是膜拜单车中地图覆盖物的效果是没有恢复原状的 因为重新加载地图覆盖物会移除掉旧的覆盖物 所以不必担心覆盖物会一直往上移或者说覆盖物只会变大一次之后第二次就没有效果 ^_^!
self.mView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
self.mView.center.y += 10
}
}
}