No Description

UIViewControllerExt.swift 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // UIViewControllerExt.swift
  3. // ExtensionKit
  4. //
  5. // Created by FFIB on 2017/9/13.
  6. // Copyright © 2017年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. //MARK: custom methods extension
  10. extension UIViewController {
  11. public func addChildControllerAndView(_ controller: UIViewController, isNavigable: Bool = true) {
  12. if isNavigable {
  13. self.navigationController?.addChildViewController(controller)
  14. self.navigationController?.view.addSubview(controller.view)
  15. }else {
  16. self.addChildViewController(controller)
  17. self.view.addSubview(controller.view)
  18. }
  19. }
  20. public func removeControllerAndViewFromParent() {
  21. self.removeFromParentViewController()
  22. self.view.removeFromSuperview()
  23. }
  24. }
  25. //MARK: notification extension
  26. extension UIViewController {
  27. public func addNotificationObserver(name: Notification.Name, selector: Selector) {
  28. NotificationCenter.default.addObserver(self, selector: selector, name: name, object: nil)
  29. }
  30. public func removeNotificationObserver(name: Notification.Name) {
  31. NotificationCenter.default.removeObserver(self, name: name, object: nil)
  32. }
  33. public func removeAllNotificationObserver() {
  34. NotificationCenter.default.removeObserver(self)
  35. }
  36. }
  37. //MARK: jump extension
  38. extension UIViewController {
  39. public func popToRootController() {
  40. navigationController?.popToRootViewController(animated: true)
  41. }
  42. public func pushController(_ vc: UIViewController) {
  43. navigationController?.pushViewController(vc, animated: true)
  44. }
  45. public func popController() {
  46. navigationController?.popViewController(animated: true)
  47. }
  48. public func popToController(_ vc: UIViewController) {
  49. navigationController?.popToViewController(vc, animated: true)
  50. }
  51. public func presentController(_ vc: UIViewController) {
  52. present(vc, animated: true, completion: nil)
  53. }
  54. public func dismissController() {
  55. dismiss(animated: true, completion: nil)
  56. }
  57. }
  58. //MARK: navigation lateral spreads to return
  59. extension UIViewController {
  60. }