这篇文章中我们主要来叙述一下上述动画效果的实现方案。主要涉及 View Controller 转场动画的知识。

我搭建了个人站点,那里有更多内容,请多多指教。点我哦!!!
Presenting a View Controller
显示一个 View Controller 主要有一下几种方式:
通过上述方式,我们可以将一个 View Controller 显示出来,而对于显示地形式,我们可以使用 UIKit 中预定义的形式,也可以自定义(即自定义转场动画)。
Customizing the Transition Animations
自定义转场动画中,主要包含以下几个组件:
实现自定义转场动画,通常按照以下几个步骤来完成
Presented View Controller
这里,我们将 Presented View Controller 本身作为其转场代理,你也可以使用单独的代理对象。
class PresentedViewController: UIViewController {
let imageView = UIImageView(image: UIImage(named: "jd_add.jpg"))
override func viewDidLoad() {
super.viewDidLoad()
// 1.设置 transitioningDelegate(转场代理)
transitioningDelegate = self
modalPresentationStyle = .custom
view.addSubview(imageView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
imageView.frame = CGRect(x: 0, y: 120, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height - 120)
}
override func touchesBegan(_ touches: Set, with event: UIEvent?) {
self.dismiss(animated: true, completion: nil)
}
} Copyright © 2009-2022 www.fjjierui.cn 青羊区广皓图文设计工作室(个体工商户)达州站 版权所有 蜀ICP备19037934号