键盘出现时隐藏页脚 - IONIC2

Adi*_*mar 7 ionic-framework ionic2 angular

我想在键盘出现时隐藏Ionic2中的页脚,我搜索了所有论坛但没有找到正确的解决方案.

这是我的页脚 -

<ion-footer>
  <div class="footer1" >
      <p>You don't have account? <span [navPush]="pushPage"> Register here</span></p>
  </div>
</ion-footer>
Run Code Online (Sandbox Code Playgroud)

Bor*_*rda 5

@Und3rTow's answer is quite right, thank you. But a boolean is not really needed:

keyboardCheck() {
 return !this.keyboard.isOpen();
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<ion-footer *ngIf="keyboardCheck()">
 ...
</ion-footer>
Run Code Online (Sandbox Code Playgroud)

You can even avoid that function too:

<ion-footer *ngIf="!keyboard.isOpen()">
 ...
</ion-footer>
Run Code Online (Sandbox Code Playgroud)


Mic*_*oye 4

您应该能够使用 ionic Keyboard API来实现此目的,更具体地说,该isOpen()方法 - 类似以下内容应该可以工作:

export class MyClass {

  showFooter: boolean = true;

  constructor(public keyboard: Keyboard) {

  }

  keyboardCheck() {
    if (this.keyboard.isOpen()) {
        // You logic goes here
        this.showFooter = false;
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在你的 HTML 中你可以使用ngIf

<ion-footer *ngIf="showFooter">
  <div class="footer1" >
      <p>You don't have account? <span [navPush]="pushPage"> Register here</span></p>
  </div>
</ion-footer>
Run Code Online (Sandbox Code Playgroud)

感谢@sebaferreras 指出,您可能需要调用resize()以便告诉内容在动态添加页眉/页脚时重新计算其尺寸。