2016-04-13 37 views
-1

在我的應用程序中,我實現了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。那我該怎麼做?

回答

1

使用layoutIfNeeded()屬性與animateWithDuration

UIView.animateWithDuration(0.2, animations: {() -> Void in 
     viewHieght.constant = 45 
     self.view.layoutIfNeeded() 
    }) 
0
viewHeight.constant = max(0, min(45, scrollView.panGestureRecognizer.translationInView(scrollView.superview).y)) 

這應該使與手勢的視圖移動但分鐘在0和最大值45

相關問題