zoukankan      html  css  js  c++  java
  • iOS自定义键盘和系统键盘切换且文本输入框一直获得焦点

    UITextView用来进行文本输入。
    方法becomeFirstResponder和resignFirstResponder可以用来进行弹出系统键盘和收下系统键盘。

    弹出系统键盘,文本输入框获得焦点。收下系统键盘,文本输入框失去焦点。那么,问题来了。

    某个条件下,如点击界面上的某个按钮,展示自定义键盘。再次点击,切换到系统键盘。
    先收下系统键盘,再展示自定义键盘。比如移动自定义键盘View的Frame.Y。但这时因为收下系统键盘,本文输入框失去焦点。
    虽然展示了自定义键盘。但用户体验很不好。光标没有闪动。自定义键盘输入的内容无法准确插入到文本输入框里。

    解决方法:(见iOS开发文档)

    @property(readwrite, retain) UIView *inputView

    If the value in this property is nil, the text view displays the standard system keyboard when it becomes first responder. Assigning a custom view to this property causes that view to be presented instead.

    The default value of this property is nil.

     

    这个属性就是说
    1.为nil时展示系统键盘。
    2.为自定义View时展示自定义键盘。

    注意要刷新。

    - (void)reloadInputViews

    You can use this method to refresh the custom input view or input accessory view associated with the current object when it is the first responder. The views are replaced immediately—that is, without animating them into place. If the current object is not the first responder, this method has no effect.

    完美解决问题。
    文本输入框一直获得焦点。自定义键盘和系统键盘自由切换。

     
  • 相关阅读:
    HTML基础之HTML标签-html header(meta,title) html body(p,br,h,form,div,span,input,lable)
    day5_非空即真非零即真
    day5_不能循环删除list-深拷贝、浅拷贝(import copy)
    day5_函数返回值
    day4_局部变量和全局变量
    day5_函数的参数
    python字符串与列表的相互转换
    python自动化返回:no tests were fount Empty test suite
    读取Excel数据封装
    测试工程题
  • 原文地址:https://www.cnblogs.com/lzihua/p/4488987.html
Copyright © 2011-2022 走看看