设置 UIView 从左上角 (0,0) 开始

Setting UIView to Start From Upper-Left Corner (0,0)

我修改了 UIPanGestureRecognizer 以使用下拉菜单关闭视图。我是这样做的,所以现在可以在 y 轴上拖动视图,如果 y 的变化大于 100,它会关闭视图。

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                   
            }
        }
}

但是,我想将视图放回原来的位置,但是我不知道如何......

此外,我的方法是一种很好的方法还是一种非常原始的方法?

能否请您尝试在 // Reposition Back 评论中添加以下代码:

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