2016-11-14 67 views
0

我有一個navBar控制器連接到UIView,我有一個正確的酒吧按鈕項目是雪佛龍。我用編程方式創建了一個搜索欄。如果你點擊約20-100倍的雪佛龍,它會不斷增長,直到它離開屏幕。我可以看到每次點擊我的搜索欄中略微凹凸的雪佛龍。由於您不能在navBar上放置約束,並且固定的空格鍵按鈕項也不起作用。任何建議在哪裏看或如何解決這個問題?Swift ios 10 NavBar項目不斷增加

func rotateChevron(animated: Bool = true) { 
    let chevAnimate = animated ? 0.3 : 0.0 
    let chevIsDown = messagePicker.frame.origin.y == self.view.frame.height - (tabBarController?.tabBar.frame.height ?? 0) 
    let rotation: CGFloat = chevIsDown ? 0.0 : 180.001 
    UIView.animate(withDuration: chevAnimate, animations: { 
     self.filterChevron.customView?.transform = CGAffineTransform(rotationAngle: rotation.degreesToRadians) 
    }, completion: nil) 
} 

回答

0

經過一番研究,我把動畫塊強制CGSize(W/H),這似乎已經解決了這個問題之內。我還發現,變換動畫不應該與幀一起使用,因爲它每次都會移動圖像的邊界,這就是人字形起伏的原因。

func rotateChevron(animated: Bool = true) { 
    let chevAnimate = animated ? 0.3 : 0.0 
    let chevIsDown = messagePicker.frame.origin.y == self.view.frame.height - (tabBarController?.tabBar.frame.height ?? 0) 
    let rotation: CGFloat = chevIsDown ? 0.0 : 180.001 
    filterChevron.customView?.frame.size = CGSize(width: 35, height: 30) 
    UIView.animate(withDuration: chevAnimate, animations: { 
     self.filterChevron.customView?.transform = CGAffineTransform(rotationAngle: rotation.degreesToRadians) 
    }, completion: nil) 
}