【问题标题】:How to move view down by animation?如何通过动画向下移动视图?
【发布时间】:2016-04-13 11:16:44
【问题描述】:

在我的应用程序中,我实现了 webview,在该 webview 下我有一个视图,我想像在 Safari 中那样通过动画来移动该视图。

这是我的代码:

func scrollViewWillBeginDragging(scrollView: UIScrollView) {
    if scrollView.panGestureRecognizer.translationInView(scrollView.superview).y > 0 {
        // scrolls down
        print("UP")
        viewbottom.hidden = false
        viewHieght.constant = 45
    } else {
        print("DOWN")
        viewbottom.hidden = true
        viewHieght.constant = 0
    }
}

在这段代码中,我在向下滚动时隐藏了视图,但我想像 Safari 一样缓慢地向下移动它。那么我该怎么做呢?

【问题讨论】:

    标签: ios swift webview core-animation


    【解决方案1】:

    layoutIfNeeded() 属性与animateWithDuration 一起使用

       UIView.animateWithDuration(0.2, animations: { () -> Void in
            viewHieght.constant = 45
            self.view.layoutIfNeeded()
       })
    

    【讨论】:

      【解决方案2】:
      viewHeight.constant = max(0, min(45, scrollView.panGestureRecognizer.translationInView(scrollView.superview).y))
      

      这应该使视图随着手势移动,但最小值为 0,最大值为 45

      【讨论】:

        猜你喜欢
        • 2015-04-19
        • 1970-01-01
        • 2012-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-01
        • 1970-01-01
        相关资源
        最近更新 更多