YYTextKeyboardManager.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // YYTextKeyboardManager.h
  3. // YYText <https://github.com/ibireme/YYText>
  4. //
  5. // Created by ibireme on 15/6/3.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. NS_ASSUME_NONNULL_BEGIN
  13. /**
  14. System keyboard transition information.
  15. Use -[YYTextKeyboardManager convertRect:toView:] to convert frame to specified view.
  16. */
  17. typedef struct {
  18. BOOL fromVisible; ///< Keyboard visible before transition.
  19. BOOL toVisible; ///< Keyboard visible after transition.
  20. CGRect fromFrame; ///< Keyboard frame before transition.
  21. CGRect toFrame; ///< Keyboard frame after transition.
  22. NSTimeInterval animationDuration; ///< Keyboard transition animation duration.
  23. UIViewAnimationCurve animationCurve; ///< Keyboard transition animation curve.
  24. UIViewAnimationOptions animationOption; ///< Keybaord transition animation option.
  25. } YYTextKeyboardTransition;
  26. /**
  27. The YYTextKeyboardObserver protocol defines the method you can use
  28. to receive system keyboard change information.
  29. */
  30. @protocol YYTextKeyboardObserver <NSObject>
  31. @optional
  32. - (void)keyboardChangedWithTransition:(YYTextKeyboardTransition)transition;
  33. @end
  34. /**
  35. A YYTextKeyboardManager object lets you get the system keyboard information,
  36. and track the keyboard visible/frame/transition.
  37. @discussion You should access this class in main thread.
  38. Compatible: iPhone/iPad with iOS6/7/8/9.
  39. */
  40. @interface YYTextKeyboardManager : NSObject
  41. - (instancetype)init UNAVAILABLE_ATTRIBUTE;
  42. + (instancetype)new UNAVAILABLE_ATTRIBUTE;
  43. /// Get the default manager (returns nil in App Extension).
  44. + (nullable instancetype)defaultManager;
  45. /// Get the keyboard window. nil if there's no keyboard window.
  46. @property (nullable, nonatomic, readonly) UIWindow *keyboardWindow;
  47. /// Get the keyboard view. nil if there's no keyboard view.
  48. @property (nullable, nonatomic, readonly) UIView *keyboardView;
  49. /// Whether the keyboard is visible.
  50. @property (nonatomic, readonly, getter=isKeyboardVisible) BOOL keyboardVisible;
  51. /// Get the keyboard frame. CGRectNull if there's no keyboard view.
  52. /// Use convertRect:toView: to convert frame to specified view.
  53. @property (nonatomic, readonly) CGRect keyboardFrame;
  54. /**
  55. Add an observer to manager to get keyboard change information.
  56. This method makes a weak reference to the observer.
  57. @param observer An observer.
  58. This method will do nothing if the observer is nil, or already added.
  59. */
  60. - (void)addObserver:(id<YYTextKeyboardObserver>)observer;
  61. /**
  62. Remove an observer from manager.
  63. @param observer An observer.
  64. This method will do nothing if the observer is nil, or not in manager.
  65. */
  66. - (void)removeObserver:(id<YYTextKeyboardObserver>)observer;
  67. /**
  68. Convert rect to specified view or window.
  69. @param rect The frame rect.
  70. @param view A specified view or window (pass nil to convert for main window).
  71. @return The converted rect in specifeid view.
  72. */
  73. - (CGRect)convertRect:(CGRect)rect toView:(nullable UIView *)view;
  74. @end
  75. NS_ASSUME_NONNULL_END