iOS 基础iOS DeveloperiOS 开发

WWDC之A Look Inside Presentation

2016-02-28  本文已影响405人  One9398

前言

本Session于iOS8 SDK发布后,对于自定义控制器Presentation行为的困难,引入了UIPresentationController类,使得能协同转场动画对象,并且对Presentation的内容管理和执行起来更简单.而与UIPresentationController相关的知识点,也有许多值得一窥.

内容

Presentation 基础

UIPresentationController的作用

UIPresentationController的用法

  // Alert & ActionSheet Presentation 使用示例
        let alertController = UIAlertController(title: "Warn", message: "It's from UIAlertController", preferredStyle: .Alert)
        alertController.addAction(UIAlertAction(title: "ButtonA", style: .Default, handler: { (action) -> Void in
            print("ButtonA clicked")
        }))
        alertController.addAction(UIAlertAction(title: "Cancel", style: .Destructive, handler: { (action) -> Void in
            print("Cancel Button clicked")
        }))
        
        presentViewController(alertController, animated: true, completion: nil)

自定义的Presentation Controller

  presentationTransitionWillBegin()
  dismissalTransitionWillBegin()
  sizeForChildContentContainer(:parentSize:) -> CGSize
  frameOfPresentedViewInContainerView() -> CGRect
  containerViewWillLayoutSubviews()
  containerViewDidLayoutSubviews()

UIContentContainer

这是iOS8新增加的协议,UIViewController和UIPresentationController都遵守该协议,主要用来帮助视图控制器的内容视图在 size 和 trait变化时进行消息的层次传递,以及对内容视图尺寸或者位置的进一步自定义调整,协议所有的方法内部都有默认的实现,官方也推荐我们先调用super实现确保变化的一致性,再进行自定义的调整.

总结

iOS8SDK发布后苹果所提出界面布局的"Adaptivity"概念,深深地反映在了Presentation使用上的一致,设备尺寸SizeClass的统一标准等等,也逐渐淡化了iOS平台上手机App和平板App的差别,也使得越来越多App能iPhone上显示良好,呈现在iPad上时UI界面也进行了自适应性的变化,也能有不错的用户体验.

上一篇下一篇

猜你喜欢

热点阅读