如何优化segue中动画的hidesBackButton代码?

时间:2017-11-22 20:00:50

标签: ios swift segue uiviewanimation

我以编程方式从DynamicVCSearchVC制作segue:

@objc func goToSearchVC() {

        let searcVC = SearchVC()

        //Hide system navigation controller back button
        searcVC.navigationItem.hidesBackButton = true
        searcVC.navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(named: "closeBtn_20"), style: .plain, target: self, action: #selector(closeBtnTapped))
        searcVC.navigationItem.title = ""

        navigationController?.pushViewController(searcVC, animated: true)
        searcVC.view.backgroundColor = .lightGray
    }

hidesBackButton执行速度非常慢,"返回"按钮在segue动画中闪烁:

hidesBackButton executes very slowly

我该如何解决这个问题?有可能优化这个吗?感谢。

1 个答案:

答案 0 :(得分:0)

我使用以下代码闪烁“后退”按钮解决了问题:

let transition:CATransition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
    transition.type = kCATransitionPush
    transition.subtype =  kCATransitionFromRight
    self.navigationController!.view.layer.addAnimation(transition, forKey: kCATransition)
    self.navigationController?.pushViewController(searchVC, animated: false)

其他类型的转换:

kCATransitionFromLeft

kCATransitionFromBottom

kCATransitionFromRight

kCATransitionFromTop