UITextField(FWKeyboard)

@interface UITextField (FWKeyboard)

文本输入框键盘管理分类

Keyboard

  • 是否启用键盘管理(自动滚动),默认NO

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_keyboardManager;
  • 设置输入框和键盘的空白间距,默认10.0

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fw_keyboardDistance;
  • 设置输入框和键盘的回弹触发最小距离,默认0始终回弹

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fw_reboundDistance;
  • 是否启用键盘后台关闭处理,退后台时收起键盘,回到前台时恢复键盘,解决系统退后台输入框跳动问题,默认NO

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_keyboardResign;
  • 是否启用点击背景关闭键盘(会继续触发其它点击事件),默认NO

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_touchResign;
  • 指定用于键盘管理滚动的scrollView,默认为nil,通过修改VC.view.frame实现

    Declaration

    Objective-C

    @property (nonatomic, weak, nullable) UIScrollView *fw_keyboardScrollView;

Return

  • 点击键盘完成按钮是否关闭键盘,默认NO,二选一

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_returnResign;
  • 设置点击键盘完成按钮是否自动切换下一个输入框,二选一

    Declaration

    Objective-C

    @property (nonatomic) BOOL fw_returnNext;
  • 设置点击键盘完成按钮的事件句柄

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) void (^)(UITextField *_Nonnull) fw_returnBlock;

Toolbar

  • 获取关联的键盘Toolbar对象,可自定义样式

    Declaration

    Objective-C

    @property (nonatomic, strong) NS_REFINED_FOR_SWIFT UIToolbar *fw_keyboardToolbar;
  • 自定义键盘Toolbar上一个按钮,支持图片|字符串等(详见FWBlock),默认朝上的箭头

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) id fw_toolbarPreviousButton;
  • 自定义键盘Toolbar下一个按钮,支持图片|字符串等(详见FWBlock),默认朝下的箭头

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) id fw_toolbarNextButton;
  • 自定义键盘Toolbar完成按钮,支持图片|字符串等(详见FWBlock),默认Done

    Declaration

    Objective-C

    @property (nonatomic, strong, nullable) id fw_toolbarDoneButton;
  • 设置Toolbar点击前一个按钮时聚焦的输入框句柄,默认nil

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) UIResponder *_Nullable (^) (UITextField *_Nonnull) fw_previousResponder;
  • 设置Toolbar点击下一个按钮时聚焦的输入框句柄,默认nil

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) UIResponder *_Nullable (^) (UITextField *_Nonnull) fw_nextResponder;
  • 设置Toolbar点击前一个按钮时聚焦的输入框tag,默认0不生效

    Declaration

    Objective-C

    @property (nonatomic) NSInteger fw_previousResponderTag;
  • 设置Toolbar点击下一个按钮时聚焦的输入框tag,默认0不生效

    Declaration

    Objective-C

    @property (nonatomic) NSInteger fw_nextResponderTag;
  • 自动跳转前一个输入框,优先使用previousResponder,其次根据responderTag查找

    Declaration

    Objective-C

    - (void)fw_goPrevious;
  • 自动跳转后一个输入框,优先使用nextResponder,其次根据responderTag查找

    Declaration

    Objective-C

    - (void)fw_goNext;
  • 获取键盘弹出时的高度,对应Key为UIKeyboardFrameEndUserInfoKey

    Declaration

    Objective-C

    - (CGFloat)fw_keyboardHeight:(nonnull NSNotification *)notification;
  • 执行键盘跟随动画,支持AutoLayout,可通过keyboardHeight:获取键盘高度

    Declaration

    Objective-C

    - (void)fw_keyboardAnimate:(nonnull NSNotification *)notification
                    animations:(nonnull void (^)(void))animations
                    completion:(void (^_Nullable)(BOOL))completion;
  • 添加Toolbar,指定标题和完成句柄,使用默认按钮

    Declaration

    Objective-C

    - (void)fw_addToolbarWithTitle:(nullable id)title
                         doneBlock:(nullable void (^)(id _Nonnull))doneBlock;

    Parameters

    title

    标题,不能点击

    doneBlock

    右侧完成按钮句柄,默认收起键盘

  • 添加Toolbar,指定居中标题、左侧上一个、下一个按钮和右边按钮

    Declaration

    Objective-C

    - (void)fw_addToolbarWithTitleItem:(nullable UIBarButtonItem *)titleItem
                          previousItem:(nullable UIBarButtonItem *)previousItem
                              nextItem:(nullable UIBarButtonItem *)nextItem
                              doneItem:(nullable UIBarButtonItem *)doneItem;

    Parameters

    titleItem

    居中标题按钮

    previousItem

    左侧前一个按钮

    nextItem

    左侧下一个按钮

    doneItem

    右侧完成按钮