|
3 | 3 |
|
4 | 4 | import WinSDK
|
5 | 5 | import class Foundation.NSNotification
|
| 6 | +import struct Foundation.NSExceptionName |
| 7 | +import struct Foundation.TimeInterval |
6 | 8 |
|
7 | 9 | /// Transition styles available when presenting view controllers.
|
8 | 10 | public enum ModalTransitionStyle: Int {
|
@@ -708,6 +710,99 @@ public class ViewController: Responder {
|
708 | 710 | NSNotification.Name(rawValue: "UIViewControllerShowDetailTargetDidChangeNotification")
|
709 | 711 | }
|
710 | 712 |
|
| 713 | + // MARK - Adding a Custom Transition or Presentation |
| 714 | + |
| 715 | + /// The delegate object that provides transition animator, interactive |
| 716 | + /// controller, and custom presentation controller objects. |
| 717 | + /// |
| 718 | + /// When the view controller's `modalPresentationStyle` property is |
| 719 | + /// `ModalPresentationStyle.custom`, the framework uses the object in this |
| 720 | + /// property to facilitate transitions and presentations for the view |
| 721 | + /// controller. The transitioning delegate object is a custom object that you |
| 722 | + /// provide and that conforms to the `ViewControllerTransitioningDelegate` |
| 723 | + /// protocol. Its job is to vend the animator objects used to animate this |
| 724 | + /// view controller's view onscreen and an optional presentation controller |
| 725 | + /// to provide any additional chrome and animations. |
| 726 | + public weak var transitioningDelegate: ViewControllerTransitioningDelegate? |
| 727 | + |
| 728 | + /// Returns the active transition coordinator object. |
| 729 | + /// |
| 730 | + /// When a presentation or dismissal is in progress, this method returns the |
| 731 | + /// transition coordinator object associated with that transition. If there is |
| 732 | + /// no in-progress transition associated with the current view controller, |
| 733 | + /// the framework checks the view controller's ancestors for a transition |
| 734 | + /// coordinator object and returns that object if it exists. You can use this |
| 735 | + /// object to create additional animations and synchronize them with the |
| 736 | + /// transition animations. |
| 737 | + /// |
| 738 | + /// Container view controllers can override this method but in most cases |
| 739 | + /// should not need to. If you do override this method, first call `super` to |
| 740 | + /// see if there is an appropriate transition coordinator to return, and, if |
| 741 | + /// there is, return it. |
| 742 | + /// |
| 743 | + /// For more information about the role of transition coordinators, see |
| 744 | + /// `ViewControllerTransitionCoordinator`. |
| 745 | + public private(set) var transitionCoordinator: ViewControllerTransitionCoordinator? |
| 746 | + |
| 747 | + /// Returns the view controller that responds to the action. |
| 748 | + /// |
| 749 | + /// This method returns the current view controller if that view controller |
| 750 | + /// overrides the method indicated by the action parameter. If the current |
| 751 | + /// view controller does not override that method, the framework walks up the |
| 752 | + /// view hierarchy and returns the first view controller that does override |
| 753 | + /// it. If no view controller handles the action, this method returns `nil`. |
| 754 | + /// |
| 755 | + /// A view controller can selectively respond to an action by returning an |
| 756 | + /// appropriate value from its `canPerformAction(_:withSender:)` method. |
| 757 | + public func targetViewController<Target: AnyObject>(forAction action: (Target) -> () -> Void, |
| 758 | + sender: Any?) -> ViewController? { |
| 759 | + fatalError("\(#function) not yet implemented") |
| 760 | + } |
| 761 | + |
| 762 | + public func targetViewController<Target: AnyObject>(forAction action: (Target) -> (_: Any?) -> Void, |
| 763 | + sender: Any?) -> ViewController? { |
| 764 | + fatalError("\(#function) not yet implemented") |
| 765 | + } |
| 766 | + |
| 767 | + /// The presentation controller that's managing the current view controller. |
| 768 | + /// |
| 769 | + /// If the view controller is managed by a presentation controller, this |
| 770 | + /// property contains that object. This property is `nil` if the view |
| 771 | + /// controller isn't managed by a presentation controller. |
| 772 | + /// |
| 773 | + /// If you've not yet presented the current view controller, accessing this |
| 774 | + /// property creates a presentation controller based on the current value in |
| 775 | + /// the `modalPresentationStyle` property. Always set the value of that |
| 776 | + /// property before accessing any presentation controllers. |
| 777 | + public private(set) var presentationController: PresentationController? |
| 778 | + |
| 779 | + /// The nearest popover presentation controller that is managing the current view controller. |
| 780 | + /// |
| 781 | + /// If the view controller or one of its ancestors is managed by a popover |
| 782 | + /// presentation controller, this property contains that object. This property |
| 783 | + /// is `nil` if the view controller is not managed by a popover presentation |
| 784 | + /// controller. |
| 785 | + /// |
| 786 | + /// If you created the view controller but have not yet presented it, accessing |
| 787 | + /// this property creates a popover presentation controller when the value in |
| 788 | + /// the `modalPresentationStyle` property is `ModalPresentationStyle.popover`. |
| 789 | + /// If the modal presentation style is a different value, this property is `nil`. |
| 790 | +#if false |
| 791 | + public private(set) var popoverPresentationController: PopoverPresentationController? |
| 792 | +#endif |
| 793 | + |
| 794 | + /// A boolean value that indicates whether an item that previously was focused |
| 795 | + /// should again become focused when the item's view controller becomes |
| 796 | + /// visible and focusable. |
| 797 | + /// |
| 798 | + /// When the value of this property is true, the item that was last focused |
| 799 | + /// automatically becomes focused when its view controller becomes visible and |
| 800 | + /// focusable. For example, if an item in the view controller is focused and a |
| 801 | + /// second view controller is presented, the original item becomes focused |
| 802 | + /// again when the second view controller is dismissed. The default value of |
| 803 | + /// this property is `true`. |
| 804 | + public var restoresFocusAfterTransition: Bool = true |
| 805 | + |
711 | 806 | // MARK - Responding to Containment Events
|
712 | 807 |
|
713 | 808 | /// Called just before the view controller is added or removed from a
|
@@ -758,6 +853,101 @@ public class ViewController: Responder {
|
758 | 853 | self.parent = nil
|
759 | 854 | }
|
760 | 855 |
|
| 856 | + /// Transitions between two of the view controller's child view controllers. |
| 857 | + /// |
| 858 | + /// This method adds the second view controller's view to the view hierarchy |
| 859 | + /// and then performs the animations defined in your animations block. After |
| 860 | + /// the animation completes, it removes the first view controller's view from |
| 861 | + /// the view hierarchy. |
| 862 | + /// |
| 863 | + /// This method is only intended to be called by an implementation of a custom |
| 864 | + /// container view controller. If you override this method, you must call |
| 865 | + /// `super` in your implementation. |
| 866 | + public func transition(from source: ViewController, |
| 867 | + to destination: ViewController, duration: TimeInterval, |
| 868 | + options: View.AnimationOptions = [], |
| 869 | + animations: (() -> Void)?, |
| 870 | + completion: ((Bool) -> Void)? = nil) { |
| 871 | + fatalError("\(#function) not yet implemented") |
| 872 | + } |
| 873 | + |
| 874 | + /// Returns a boolean value indicating whether appearance methods are |
| 875 | + /// forwarded to child view controllers. |
| 876 | + /// |
| 877 | + /// This method is called to determine whether to automatically forward |
| 878 | + /// appearance-related containment callbacks to child view controllers. |
| 879 | + /// |
| 880 | + /// The default implementation returns true. Subclasses of the `ViewController` |
| 881 | + /// class that implement containment logic may override this method to control |
| 882 | + /// how these methods are forwarded. If you override this method and return |
| 883 | + /// `false`, you are responsible for telling the child when its views are going |
| 884 | + /// to appear or disappear. You do this by calling the child view controller's |
| 885 | + /// `beginAppearanceTransition(_:animated:)` and `endAppearanceTransition()` |
| 886 | + /// methods. |
| 887 | + public private(set) var shouldAutomaticallyForwardAppearanceMethods: Bool = true |
| 888 | + |
| 889 | + /// Tells a child controller its appearance is about to change. |
| 890 | + /// |
| 891 | + /// If you are implementing a custom container controller, use this method to |
| 892 | + /// tell the child that its views are about to appear or disappear. Do not |
| 893 | + /// invoke `viewWillAppear(_:)`, `viewWillDisappear(_:)`, `viewDidAppear(_:)`, |
| 894 | + /// or `viewDidDisappear(_:)` directly. |
| 895 | + public func beginAppearanceTransition(_ isAppearing: Bool, animated: Bool) { |
| 896 | + fatalError("\(#function) not yet implemented") |
| 897 | + } |
| 898 | + |
| 899 | + /// Tells a child controller its appearance has changed. |
| 900 | + /// |
| 901 | + /// If you are implementing a custom container controller, use this method to |
| 902 | + /// tell the child that the view transition is complete. |
| 903 | + public func endAppearanceTransition() { |
| 904 | + fatalError("\(#function) not yet implemented") |
| 905 | + } |
| 906 | + |
| 907 | + /// Changes the traits assigned to the specified child view controller. |
| 908 | + /// |
| 909 | + /// Usually, traits are passed unmodified from the parent view controller to |
| 910 | + /// its child view controllers. When implementing a custom container view |
| 911 | + /// controller, you can use this method to change the traits of any embedded |
| 912 | + /// child view controllers to something more appropriate for your layout. |
| 913 | + /// Making such a change alters other view controller behaviors associated |
| 914 | + /// with that child. For example, modal presentations behave differently in a |
| 915 | + /// horizontally compact versus horizontally regular environment. You might |
| 916 | + /// also make such a change to force the same set of traits on the child view |
| 917 | + /// controller regardless of the actual trait environment. |
| 918 | + public func setOverrideTraitCollection(_ collection: TraitCollection?, |
| 919 | + forChild childViewController: ViewController) { |
| 920 | + fatalError("\(#function) not yet implemented") |
| 921 | + } |
| 922 | + |
| 923 | + /// Retrieves the trait collection for a child view controller. |
| 924 | + /// |
| 925 | + /// Use this method to retrieve the trait collection for a child view |
| 926 | + /// controller. You can then modify the trait collection for the designated |
| 927 | + /// child view controller and set it using the |
| 928 | + /// `setOverrideTraitCollection(_:forChild:)` method. |
| 929 | + public func overrideTraitCollection(forChild childViewController: ViewController) |
| 930 | + -> TraitCollection? { |
| 931 | + fatalError("\(#function) not yet implemented") |
| 932 | + } |
| 933 | + |
| 934 | + /// Raised if the view controller hierarchy is inconsistent with the view |
| 935 | + /// hierarchy. |
| 936 | + /// |
| 937 | + /// When a view controller's view is added to the view hierarchy, the system |
| 938 | + /// walks up the view hierarchy to find the first parent view that has a view |
| 939 | + /// controller. That view controller must be the parent of the view controller |
| 940 | + /// whose view is being added. Otherwise, this exception is raised. This |
| 941 | + /// consistency check is also performed when a view controller is added as a |
| 942 | + /// child by calling the `addChild(_:)` method. |
| 943 | + /// |
| 944 | + /// It is also allowed for a view controller that has no parent to add its |
| 945 | + /// view to the view hierarchy. This is generally not recommended, but is |
| 946 | + /// useful in some special cases. |
| 947 | + public class var hierarchyInconsistencyException: NSExceptionName { |
| 948 | + NSExceptionName(rawValue: "UIViewControllerHierarchyInconsistencyException") |
| 949 | + } |
| 950 | + |
761 | 951 | // MARK - Getting Other Related View Controllers
|
762 | 952 |
|
763 | 953 | /// The view controller that presented this view controller.
|
@@ -844,3 +1034,30 @@ extension ViewController: ContentContainer {
|
844 | 1034 | public func systemLayoutFittingSizeDidChange(forChildContentContainer container: ContentContainer) {
|
845 | 1035 | }
|
846 | 1036 | }
|
| 1037 | + |
| 1038 | +extension ViewController: TraitEnvironment { |
| 1039 | + public var traitCollection: TraitCollection { |
| 1040 | + // The first item in the chain provides the base trait collection. |
| 1041 | + var traits: TraitCollection = |
| 1042 | + self.parent?.traitCollection |
| 1043 | + ?? self.view.superview?.traitCollection |
| 1044 | + ?? (self.view as? Window)?.traitCollection |
| 1045 | + ?? TraitCollection() |
| 1046 | + |
| 1047 | + // The parent view controller may provide overrides for the controller. |
| 1048 | + if let overrides = self.parent?.overrideTraitCollection(forChild: self) { |
| 1049 | + traits = TraitCollection(traitsFrom: [traits, overrides]) |
| 1050 | + } |
| 1051 | + |
| 1052 | + // The presentation controller may further override the traits. |
| 1053 | + if let overrides = self.presentationController?.overrideTraitCollection { |
| 1054 | + traits = TraitCollection(traitsFrom: [traits, overrides]) |
| 1055 | + } |
| 1056 | + |
| 1057 | + return traits |
| 1058 | + } |
| 1059 | + |
| 1060 | + public func traitCollectionDidChange(_ previousTraitCollection: TraitCollection?) { |
| 1061 | + // extension point for derived types |
| 1062 | + } |
| 1063 | +} |
0 commit comments