我已经创建了一个演示导航抽屉,通过预设置一个具有从左到右的自定义动画的控制器。当我们解除控制器时,我们应用从右到左的动画。虽然它能够工作,但是抽屉动画看起来并不像原生Android抽屉那样流畅。所以请问您如何最好地实现这一点,尽管我不想依赖于任何第三方库来实现此功能。
@IBAction func actionMenu(_ sender: Any) {
let controler:DrawerController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DrawerController")
as! DrawerController
let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
transition.timingFunction = CAMediaTimingFunction(name:kCAMediaTimingFunctionDefault)
view.window!.layer.add(transition, forKey: kCATransition)
present(controler, animated: false) {
controler.drawerView.backgroundColor = UIColor.black
controler.drawerView.alpha = 0.6
}
}
以下是故事板截图:
![此处应有图片描述](https://istack.dev59.com/xH2pI.webp)
![此处应有图片描述](https://istack.dev59.com/P7AlS.gif)