IQUIView+Hierarchy.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // IQUIView+Hierarchy.h
  3. // https://github.com/hackiftekhar/IQKeyboardManager
  4. // Copyright (c) 2013-16 Iftekhar Qurashi.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included in
  14. // all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. // THE SOFTWARE.
  23. #import <UIKit/UIView.h>
  24. #import <UIKit/UIViewController.h>
  25. #import "IQKeyboardManagerConstants.h"
  26. @class UICollectionView, UIScrollView, UITableView, UISearchBar, NSArray;
  27. /**
  28. UIView hierarchy category.
  29. */
  30. @interface UIView (IQ_UIView_Hierarchy)
  31. ///----------------------
  32. /// @name viewControllers
  33. ///----------------------
  34. /**
  35. Returns the UIViewController object that manages the receiver.
  36. */
  37. @property (nullable, nonatomic, readonly, strong) UIViewController *viewContainingController;
  38. /**
  39. Returns the topMost UIViewController object in hierarchy.
  40. */
  41. @property (nullable, nonatomic, readonly, strong) UIViewController *topMostController;
  42. /**
  43. Returns the UIViewController object that is actually the parent of this object. Most of the time it's the viewController object which actually contains it, but result may be different if it's viewController is added as childViewController of another viewController.
  44. */
  45. @property (nullable, nonatomic, readonly, strong) UIViewController *parentContainerViewController;
  46. ///-----------------------------------
  47. /// @name Superviews/Subviews/Siglings
  48. ///-----------------------------------
  49. /**
  50. Returns the superView of provided class type.
  51. */
  52. -(nullable UIView*)superviewOfClassType:(nonnull Class)classType;
  53. /**
  54. Returns all siblings of the receiver which canBecomeFirstResponder.
  55. */
  56. @property (nonnull, nonatomic, readonly, copy) NSArray<__kindof UIView*> *responderSiblings;
  57. /**
  58. Returns all deep subViews of the receiver which canBecomeFirstResponder.
  59. */
  60. @property (nonnull, nonatomic, readonly, copy) NSArray<__kindof UIView*> *deepResponderViews;
  61. ///-------------------------
  62. /// @name Special TextFields
  63. ///-------------------------
  64. /**
  65. Returns searchBar if receiver object is UISearchBarTextField, otherwise return nil.
  66. */
  67. @property (nullable, nonatomic, readonly) UISearchBar *textFieldSearchBar;
  68. /**
  69. Returns YES if the receiver object is UIAlertSheetTextField, otherwise return NO.
  70. */
  71. @property (nonatomic, getter=isAlertViewTextField, readonly) BOOL alertViewTextField;
  72. ///----------------
  73. /// @name Transform
  74. ///----------------
  75. /**
  76. Returns current view transform with respect to the 'toView'.
  77. */
  78. -(CGAffineTransform)convertTransformToView:(nullable UIView*)toView;
  79. ///-----------------
  80. /// @name Hierarchy
  81. ///-----------------
  82. /**
  83. Returns a string that represent the information about it's subview's hierarchy. You can use this method to debug the subview's positions.
  84. */
  85. @property (nonnull, nonatomic, readonly, copy) NSString *subHierarchy;
  86. /**
  87. Returns an string that represent the information about it's upper hierarchy. You can use this method to debug the superview's positions.
  88. */
  89. @property (nonnull, nonatomic, readonly, copy) NSString *superHierarchy;
  90. /**
  91. Returns an string that represent the information about it's frame positions. You can use this method to debug self positions.
  92. */
  93. @property (nonnull, nonatomic, readonly, copy) NSString *debugHierarchy;
  94. @end
  95. @interface UIViewController (IQ_UIView_Hierarchy)
  96. -(nullable UIViewController*)parentIQContainerViewController;
  97. @end
  98. /**
  99. NSObject category to used for logging purposes
  100. */
  101. @interface NSObject (IQ_Logging)
  102. /**
  103. Short description for logging purpose.
  104. */
  105. @property (nonnull, nonatomic, readonly, copy) NSString *_IQDescription;
  106. @end