快速平移手势
首先将greenview拉入画面中,并设定好自动布局
接下来搜寻Pan Gesture Recognizer拉入greenView里面
我们先设定全域变数
var lastLocation = CGPoint(x:0,y:0)
随后将潘手势拉入程式码里产生IB动作
@IBAction func panAction(_发送者:UIPanGestureRecognizer){
如果sender.state == .be {
lastLocation = greenView.center
}否则,如果sender.state == .changed {
让翻译= sender.translation(in:greenView)
greenView.center = CGPoint(x:lastLocation.x + translation.x
,y:lastLocation.y + translation.y)
}
}
使用程式码产生
先设定要对应的方法