Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var startingFrame: CGRect?
- @objc func acknowledgeSwiped(sender: UIPanGestureRecognizer) {
- if let sliderView = sender.view {
- let translation = sender.translation(in: swipeView)
- switch sender.state {
- case .began:
- startingFrame = swipeImage.frame
- fallthrough
- case .changed:
- if let startFrame = startingFrame {
- var movex = translation.x
- if movex < -startFrame.origin.x { movex = -startFrame.origin.x }
- let xMax = swipeView.frame.width - startFrame.origin.x - startFrame.width
- if movex > xMax {
- movex = xMax
- acknowledge()
- }
- var movey = translation.y
- if movey < -startFrame.origin.y { movey = -startFrame.origin.y }
- let yMax = swipeView.frame.height - startFrame.origin.y - startFrame.height
- if movey > yMax {
- movey = yMax
- }
- sliderView.transform = CGAffineTransform(translationX: movex, y: movey)
- }
- default: // .ended and others:
- UIView.animate(withDuration: 0.1, animations: {
- sliderView.transform = CGAffineTransform.identity
- })
- }
- }
- }
Add Comment
Please, Sign In to add comment