ios8中 利用UIPresentationController 自訂轉場

來源:互聯網
上載者:User

ios8中 利用UIPresentationController 自訂轉場

1、UIPresentationController 介紹

UIPresentationController 是 iOS8 新增的一個 API,用來控制 controller 之間的跳轉特效。比如希望實現一個特效,顯示一個視窗,大小和位置都是自訂的,並且遮罩在原來的頁面上。在之前,可以操作view的一些方法來實現。

2、使用介紹

1. 設定目標控制器的 轉場代理 和 展示方法

controller.modalPresentationStyle = UIModalPresentationStyle.Custom// 設定 動畫樣式controller.transitioningDelegate = transtinoDelegate// 此對象要實現 UIViewControllerTransitioningDelegate 協議

2. transtionDelegate 實現 UIViewControllerTransitioningDelegate 協議方法

// 返回控制控制器彈齣動畫的對象optional func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning?// 返回控制控制器消失動畫的對象optional func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?@availability(iOS, introduced=8.0)// 返回控制控制器跳轉的對象optional func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController!, sourceViewController source: UIViewController) -> UIPresentationController?

3. 控制控制器跳轉的類

控制控制器跳轉的類繼承自 UIPresentationController

/*構造方法:參數:presentedViewController將要跳轉到的目標控制器presentingViewController跳轉前的原控制器*/init(presentedViewController: UIViewController!, presentingViewController: UIViewController!)

常用的屬性和方法
presentedViewController:要 modal 顯示的視圖控制器presentingViewController:低層的視圖控制器containerView()[內容] 檢視presentedView()被展現的視圖func presentationTransitionWillBegin()跳轉將要開始func presentationTransitionDidEnd(completed: Bool)跳轉完成func dismissalTransitionWillBegin()dismiss 將要開始func dismissalTransitionDidEnd(completed: Bool)dismiss 完成func frameOfPresentedViewInContainerView()目標 控制器設定

4. 控制動畫類

控制動畫對類繼承自 UIViewControllerAnimatedTransitioning

// 執行動畫的時間func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval// 動畫過程設定func animateTransition(transitionContext: UIViewControllerContextTransitioning)

5. 總結

1. 設定目標控制器的轉場代理

2. 專場代理返回三個對象用於控制轉場過程

3. 控制控制器轉場對象,可以在此做專場前後的操作,例如添加遮罩等

4. 控制轉場動畫,用於設定目標控制器出現或消失的動畫,以及控制器的大小樣式等。

3. API 詳細介紹

稍後。。。

4.自訂跳轉 Demo

稍後。。。


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.