Swift ios 10 NavBar物品不断增长

时间:2016-11-14 19:43:56

标签: swift animation uinavigationbar

我有一个连接到UIView的navBar控制器,我有一个正确的条形按钮项目,这是一个雪佛龙。我已经以编程方式创建了一个搜索栏。如果你点击人字形大约20-100倍,它会不断增长,直到离开屏幕。我每次点击雪佛龙时都会看到我的搜索栏中有轻微的凹凸。由于您无法在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)
}

1 个答案:

答案 0 :(得分: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)
}