本文主要是介绍Swit轉場動畫的簡單分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先, 我們得了解什麼是轉場動畫.
1. 轉場動畫即是對一個view呈現和關閉時所做的動畫, 叫轉場動畫.
動畫是如何做出來的呢?
一. 了解CALayer與CGContext和UIView之間的關係
1. 以前我們學習UIView的時候, 應該知道, 當創建一個UIView的時候,系統會默認將UIView的LayerClass設置為layer類型.那麼什麼是layer呢?
-1.1 layer即是圖層, 是CALayer類型的實例. 而CALayer包含在QuartzCore框架中,這是一個跨平台的框架,即可以用在ios中又可以用在Mac OS X中.在使用Core Animation開發動畫的本質就是將CALayer中的內容轉化為位圖從而供硬件操作,所以要熟練掌握動畫操作必須先熟悉CALayer.
-1.2 又多一個問題了, 那麼CALayer是什麼?首先, UIView有一個屬性是layer, 在這個屬性有下面這麼一段注析
: public var layer: CALayer { get } // returns view's layer. Will always return a non-nil value. view is layer's delegate
public init()
public init(layer: AnyObject)
public func presentationLayer() -> AnyObject?
public func modelLayer() -> AnyObject
public class func defaultValueForKey(key: String) -> AnyObject?
public class func needsDisplayForKey(key: String) -> Bool
public func shouldArchiveValueForKey(key: String) -> Bool
public var bounds: CGRect
public var position: CGPoint
等等......太多了就不列出來了, 這裡只做個簡單的分析.
override func drawLayer(layer: CALayer, inContext ctx: CGContext)
public func CGContextScaleCTM(c: CGContext?, _ sx: CGFloat, _ sy: CGFloat)
@available(iOS 2.0, *)
public func CGContextTranslateCTM(c: CGContext?, _ tx: CGFloat, _ ty: CGFloat)
二. 轉場動畫的實現
@available(iOS 4.0, *)
public class func animateWithDuration(duration: NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations: () -> Void, completion: ((Bool) -> Void)?)
@available(iOS 4.0, *)
public class func animateWithDuration(duration: NSTimeInterval, animations: () -> Void, completion: ((Bool) -> Void)?)
@available(iOS 4.0, *)
public class func animateWithDuration(duration: NSTimeInterval, animations: () -> Void)
@available(iOS 4.0, *)
public class func transitionWithView(view: UIView, duration: NSTimeInterval, options: UIViewAnimationOptions, animations: (() -> Void)?, completion: ((Bool) -> Void)?)
ContainerView: 容器視圖, 用於存放動畫所需要的控件,所有跟動畫有關的控件都放在裡面.
1. func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController?
2. func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning?
3.func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?
这篇关于Swit轉場動畫的簡單分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!