十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問題一站解決
這篇文章中我們主要來敘述一下上述動(dòng)畫效果的實(shí)現(xiàn)方案。主要涉及 View Controller 轉(zhuǎn)場(chǎng)動(dòng)畫的知識(shí)。
我搭建了個(gè)人站點(diǎn),那里有更多內(nèi)容,請(qǐng)多多指教。點(diǎn)我哦?。?!
Presenting a View Controller
顯示一個(gè) View Controller 主要有一下幾種方式:
通過上述方式,我們可以將一個(gè) View Controller 顯示出來,而對(duì)于顯示地形式,我們可以使用 UIKit 中預(yù)定義的形式,也可以自定義(即自定義轉(zhuǎn)場(chǎng)動(dòng)畫)。
Customizing the Transition Animations
自定義轉(zhuǎn)場(chǎng)動(dòng)畫中,主要包含以下幾個(gè)組件:
實(shí)現(xiàn)自定義轉(zhuǎn)場(chǎng)動(dòng)畫,通常按照以下幾個(gè)步驟來完成
Presented View Controller
這里,我們將 Presented View Controller 本身作為其轉(zhuǎn)場(chǎng)代理,你也可以使用單獨(dú)的代理對(duì)象。
class PresentedViewController: UIViewController { let imageView = UIImageView(image: UIImage(named: "jd_add.jpg")) override func viewDidLoad() { super.viewDidLoad() // 1.設(shè)置 transitioningDelegate(轉(zhuǎn)場(chǎng)代理) 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) } }