cdts/xdts-ios 3/TreeHole/CYHResetCode/CYH/QMUIKit/QMUIComponents/QMUIKeyboardManager.h

272 lines
11 KiB
C
Raw Normal View History

2023-07-27 09:20:00 +08:00
/**
* Tencent is pleased to support the open source community by making QMUI_iOS available.
* Copyright (C) 2016-2021 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/
//
// QMUIKeyboardManager.h
// qmui
//
// Created by QMUI Team on 2017/3/23.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@protocol QMUIKeyboardManagerDelegate;
@class QMUIKeyboardUserInfo;
/**
* `QMUIKeyboardManager` 便使 UI
* App A B 使 firstResponder `QMUIKeyboardManager` `delegateEnabled` `targetResponder` 便 firstResponder UIResponder UIResponder
* QMUIKeyboardManager
*
* 使
* 1. 使 initWithDelegate:
* 2. addTargetResponder:
* 3. delegate keyboardWillChangeFrameWithUserInfo:
*
* QMUIKeyboardManager UITextField(QMUI) UITextView(QMUI)
* @see UITextField(QMUI)
* @see UITextView(QMUI)
*/
@interface QMUIKeyboardManager : NSObject
/**
* delegate
*/
- (instancetype)initWithDelegate:(id<QMUIKeyboardManagerDelegate>)delegate NS_DESIGNATED_INITIALIZER;
/**
* delegate
*/
@property(nonatomic, weak, readonly) id<QMUIKeyboardManagerDelegate> delegate;
/**
* delegate的回调 UIViewController viewWillAppear: viewWillDisappear:
* YES
*/
@property(nonatomic, assign) BOOL delegateEnabled;
/**
* `applicationState` NO `UIApplicationStateActive` YES state
*/
@property(nonatomic, assign) BOOL ignoreApplicationState UI_APPEARANCE_SELECTOR;
+ (instancetype)appearance;
/**
* UIResponder UITextView UITextField targetResponder UIResponder
* YESNO
*/
- (BOOL)addTargetResponder:(UIResponder *)targetResponder;
/**
* target UIResponder nil
*/
- (NSArray<UIResponder *> *)allTargetResponders;
/**
* targetResponder keyboardManager YES
*/
- (BOOL)removeTargetResponder:(UIResponder *)targetResponder;
/**
* rect转为相对于view的rectrect转化为相对于当前 self.view rect y viewiPad的键盘
* @param rect rect keyboardUserInfo.endFrame
* @param view view或者windownil则相对有当前的 mainWindow
*/
+ (CGRect)convertKeyboardRect:(CGRect)rect toView:(UIView *)view;
/**
* view底部的距离endFrame.size.height或者visibleKeyboardHeightiPad浮动键盘的时候就包括了底部的空隙使
*/
+ (CGFloat)distanceFromMinYToBottomInView:(UIView *)view keyboardRect:(CGRect)rect;
/**
* view的位置即可
*/
+ (void)animateWithAnimated:(BOOL)animated keyboardUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;
/**
* iPad Pro 使willShow的通知willShow回调来显示targetResponder的场景targetResponder正常的显示出来show和hide的状态就好了 iPad Pro
* @param showBlock blockshowBlock理解为系统的show通知
* @param hideBlock blockhideBlock理解为系统的hide通知UI回到默认状态
*/
+ (void)handleKeyboardNotificationWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo showBlock:(void (^)(QMUIKeyboardUserInfo *keyboardUserInfo))showBlock hideBlock:(void (^)(QMUIKeyboardUserInfo *keyboardUserInfo))hideBlock;
/**
* viewnil
*/
+ (UIView *)keyboardView;
/**
* windownil
*/
+ (UIWindow *)keyboardWindow;
/**
*
*/
+ (BOOL)isKeyboardVisible;
/**
* frame
*/
+ (CGRect)currentKeyboardFrame;
/**
*
*/
+ (CGFloat)visibleKeyboardHeight;
@end
@interface QMUIKeyboardUserInfo : NSObject
/**
* KeyboardManager
*/
@property(nonatomic, weak, readonly) QMUIKeyboardManager *keyboardManager;
/**
* notification
*/
@property(nonatomic, strong, readonly) NSNotification *notification;
/**
* notification自带的userInfo
*/
@property(nonatomic, strong, readonly) NSDictionary *originUserInfo;
/**
* UIResponder `targetResponder` `addTargetResponder:` UIResponder UIResponder
*/
@property(nonatomic, weak, readonly) UIResponder *targetResponder;
/**
*
*/
@property(nonatomic, assign, readonly) CGFloat width;
/**
*
*/
@property(nonatomic, assign, readonly) CGFloat height;
/**
* view上的可见高度view重叠的高度view=nil
*/
- (CGFloat)heightInView:(UIView *)view;
/**
* beginFrame
*/
@property(nonatomic, assign, readonly) CGRect beginFrame;
/**
* endFrame
*/
@property(nonatomic, assign, readonly) CGRect endFrame;
/**
* duration0
*/
@property(nonatomic, assign, readonly) NSTimeInterval animationDuration;
/**
* Curve参数
*/
@property(nonatomic, assign, readonly) UIViewAnimationCurve animationCurve;
/**
* Options参数
*/
@property(nonatomic, assign, readonly) UIViewAnimationOptions animationOptions;
/**
*
*/
@property(nonatomic, assign, readonly) BOOL isFloatingKeyboard;
@end
/**
* `QMUIKeyboardManagerDelegate`delegate名字`QMUIKeyboardUserInfo`userInfo做了一个封装便userInfo的属性值
*/
@protocol QMUIKeyboardManagerDelegate <NSObject>
@optional
/**
*
*/
- (void)keyboardWillShowWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo;
/**
*
*/
- (void)keyboardWillHideWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo;
/**
* frame即将发生变化
* delegate除了对应系统的willChangeFrame通知外iPad下还增加了监听键盘frame变化的KVO来处理浮动键盘view跟随键盘运动delegate里面实现willShow和willHide在手机上是准确的iPad的浮动键盘下是不准确的
*/
- (void)keyboardWillChangeFrameWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo;
/**
*
*/
- (void)keyboardDidShowWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo;
/**
*
*/
- (void)keyboardDidHideWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo;
/**
* frame已经发生变化
*/
- (void)keyboardDidChangeFrameWithUserInfo:(QMUIKeyboardUserInfo *)keyboardUserInfo;
@end
@interface UIResponder (KeyboardManager)
/// 持有KeyboardManager对象
@property(nonatomic, strong) QMUIKeyboardManager *qmui_keyboardManager;
@end
@interface UITextField (QMUI_KeyboardManager)
/// 键盘相关block搭配QMUIKeyboardManager一起使用
@property(nonatomic, copy) void (^qmui_keyboardWillShowNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardWillHideNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardWillChangeFrameNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardDidShowNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardDidHideNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardDidChangeFrameNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@end
@interface UITextView (QMUI_KeyboardManager)
/// 键盘相关block搭配QMUIKeyboardManager一起使用
@property(nonatomic, copy) void (^qmui_keyboardWillShowNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardWillHideNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardWillChangeFrameNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardDidShowNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardDidHideNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@property(nonatomic, copy) void (^qmui_keyboardDidChangeFrameNotificationBlock)(QMUIKeyboardUserInfo *keyboardUserInfo);
@end