2016-11-14 40 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) 
}