如何在滑动时向下移动图像视图?

时间:2014-07-14 23:55:17

标签: ios swift uigesturerecognizer

我有一个图片视图,我需要用户向下滑动此图片,但我不知道该怎么做。我把日志知道是否刷了它的工作和它的工作状态,我希望当我滑动时图像移动。我是iOS的新手。你能救我吗?

这是我的ViewController类:

class MainScreenViewController: UIViewController {

    @IBOutlet var buttonMenuEntry: UIButton
    @IBOutlet var buttonMenuExit: UIButton
    @IBOutlet var mainscreenEntryView: UIImageView
    @IBOutlet var mainscreenCard: UIImageView

    override func viewDidLoad() {
        super.viewDidLoad()

        var swipeCardDown = UISwipeGestureRecognizer(target: self, action: "respondToGesture:")
        swipeCardDown.direction = UISwipeGestureRecognizerDirection.Down
        self.mainscreenCard.addGestureRecognizer(swipeCardDown)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func buttonMenuClicked(sender: UIButton){

        buttonMenuEntry.hidden = true
        buttonMenuExit.hidden = false
    }

    func respondToGesture(gesture: UIGestureRecognizer){
        println("Swiped down")

    }
}

感谢。

1 个答案:

答案 0 :(得分:2)

最简单的方法是:

func respondToGesture(gesture: UIGestureRecognizer){
    UIView.animateWithDuration(0.35, animations: {

            mainscreenCard.frame = CGRectMake(mainscreenCard.frame.origin.x,
                self.view.frame.height,
                mainscreenCard.frame.size.width,
                mainscreenCard.frame.size.height)
        })

}

根据需要调整时间