
I add a view to self.view, and add a UIPangestureRecognizer to the view, move the view, but not fluency, I can feel not fluency,
this my code, thanks you help me
var redView:UIView = UIView();
var redFrame:CGRect = CGRect();
override func viewDidLoad() {
super.viewDidLoad()
redView = UIView.init(frame: CGRect.init(x: 0, y: 100, width: KWidth, height: 40))
redView.backgroundColor = UIColor.red
self.redFrame = redView.frame;
self.view.addSubview(redView);
let pan:UIPanGestureRecognizer = UIPanGestureRecognizer.init(target: self, action: #selector(moveFunction(pan:)))
self.redView.addGestureRecognizer(pan)
}
func moveFunction(pan:UIPanGestureRecognizer) {
let point:CGPoint = pan.translation(in: self.view)
pan.setTranslation(CGPoint.zero, in: self.view)
if pan.state == .changed{
print(point)
let redY:CGFloat = redView.frame.origin.y + point.y
redView.frame = CGRect.init(x: 0, y: Int(redY), width: KWidth, height: 40)
}
}
Use UIView animation on set frame with 0.05 of animation duration.