首页 文章

Ionic 2/3 WhatsApp就像信使功能一样

提问于
浏览
1

我正在尝试使用JavaScript实现类似于Ionic 3的WhatsApp信使功能,并遇到了键盘问题 . 当我单击输入文本区域时,键盘将按键盘打开的数量移动整个App . 如果我使用以下代码禁用滚动功能,那么我的输入文本区域字段将隐藏在键盘后面 .

我想要的是禁用Scroll但输入文本区域与键盘一起向上移动 . 有谁知道如何巧妙地解决这个问题?非常感谢!!

{
        platforms : {
          ios : {
            scrollAssist: false,  
            autoFocusAssist: false 
          }
        }
      }

2 回答

  • 0

    如果我理解你正确看keyboard plugin它有方法disableScroll(禁用)

  • 0

    首先要做的是使用 ionic-plugin-keyboard 来阻止本机浏览器向上推/滚动内容窗格,并允许键盘滑过并覆盖现有内容:

    constructor(private keyboard: Keyboard) {
      this.platform.ready().then(() => {
        // ...
    
        this.keyboard.disableScroll(false); // <- like this
    
        // ...
    }
    

    NoteKeyboard.disableScroll() 支持ios和windows only .

    是的,这解决了部分问题 . 另一部分是我的输入文本框现在隐藏在打开的键盘后面 .

    就像你在this OS answer中看到的一样,我've found that the following configuration seems to work better (keeping in mind that there'还有一些与键盘相关的问题仍然存在):

    @NgModule({
        declarations: [
            MyApp,
            //...
        ],
        imports: [
            //...
            IonicModule.forRoot(MyApp, {
                scrollPadding: false,
                scrollAssist: true,
                autoFocusAssist: false
            })
        ],
        bootstrap: [IonicApp],
        entryComponents: [
            // ...
        ],
        providers: [
            // ...
        ]
    })
    export class AppModule { }
    

    关键是 scrollPadding: falsescrollAssist: true :保持 scrollAssist: true 我们避免输入被键盘隐藏,如果它靠近页面底部,并且通过设置 scrollPadding: false 我们还避免了一些与空白空格相关的奇怪错误隐藏后键盘 .

相关问题