視頻教程Swift零基礎(chǔ)學(xué)習(xí)之手勢移動(dòng)圖片App開發(fā)
1、創(chuàng)建一個(gè)項(xiàng)目
創(chuàng)建好了,我運(yùn)行一下
2、添加圖片到項(xiàng)目中
3侦高、添加image view到storeboard
4、添加Pan Gesture Recognizor到storyboard
5厌杜、添加image view的outlet和pan的action
6奉呛、將下面代碼復(fù)制到函數(shù)中
7、運(yùn)行效果
let translation = sender.translation(in: self.view)
imageView.center = CGPoint(x:imageView.center.x + translation.x,y:imageView.center.y + translation.y)
sender.setTranslation(CGPoint.zero, in: self.view)