I adapted a UIPanGestureRecognizer to use pull-down to dismiss view. I made it like this, so now the view can be dragged the in y-axis and if change in y is greater than 100, it dismisses the view.
override func viewDidLoad() {
super.viewDidLoad()
let myPanGestureRecognizer = UIPanGestureRecognizer(target: self, action: "myPanAction:")
self.player.view.addGestureRecognizer(myPanGestureRecognizer)
}
func myPanAction(recognizer: UIPanGestureRecognizer) {
let translation = recognizer.translationInView(self.view)
if let myView = recognizer.view {
myView.center = CGPoint(x: myView.center.x, y: myView.center.y + translation.y)
}
recognizer.setTranslation(CGPointZero, inView: self.view)
if recognizer.state == UIGestureRecognizerState.Ended {
let velocity = recognizer.velocityInView(self.view)
if velocity.y > 100 {
dismissViewControllerAnimated(true, completion: nil)
} else {
// Reposition Back
}
}
}
However, I want to position the view back to its original place but, I couldn't figure out how..
Also, is my approach a good way of doing it or is it a very primitive approach?
Can you please try to add on the // Reposition Back
comment the following code:
let frame = myView.frame // Get the current view frame
frame.origin = CGPointZero // Change the frame origin to x:0 y:0
myView.frame = frame // Change the myView frame to frame
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.