标签:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
import UIKit class ViewController : UIViewController { @IBOutlet weak var imageView: UIImageView ! var dynamicAnimator = UIDynamicAnimator () var snap: UISnapBehavior ? override func viewDidLoad() { super .viewDidLoad() dynamicAnimator = UIDynamicAnimator (referenceView: self .view) } @IBAction func tapped(sender: AnyObject ){ //获取点击位置 let tap = sender as ! UITapGestureRecognizer let point = tap.locationInView( self .view) //删除之前的吸附,添加一个新的 if self .snap != nil { self .dynamicAnimator.removeBehavior( self .snap!) } self .snap = UISnapBehavior (item: self .imageView, snapToPoint: point) self .dynamicAnimator.addBehavior( self .snap!) } override func didReceiveMemoryWarning() { super .didReceiveMemoryWarning() } } |
Swift - 使用UI Dynamics给UIKit组件添加移动吸附行为
标签:
原文地址:http://www.cnblogs.com/Free-Thinker/p/4858369.html