End mobile form page content keyboard blocking text box problems beyond

<ion-input (ionFocus)="checkFocus($event)" (ionBlur)="checkBlur()" type="text" [(ngModel)]="name"></ion-input>

checkFocus(e, line) {
    this.canScroll = true;
    let hei = this.content.contentHeight;
    let scrollHeight;
    let availabeHei = hei - scrollHeight;
    if (availabeHei < e._keyboardHeight) {
      this.cardCon.nativeElement.style.marginBottom = e._keyboardHeight + "px";
    }
    this.scrollLen = e._keyboardHeight - availabeHei;
    this.content.scrollTo(0,this.scrollLen, 200);
  }
  checkBlur() {
    if(this.canScroll){
      this.canScroll = false;
      this.card.nativeElement.style.marginBottom = 0 + "px";
      this.content.scrollTo(0, -this.scrollLen, 200);
    }
  }

   @ViewChild("card") card: ElementRef;
  @ViewChild(Content) content: Content;
  constructor(private keyboard: Keyboard, public service: MobileEndService) {
    /* this.keyboard.didShow.subscribe({
      next: (value) => {
        console.log(value + '显示:');
        this.card.nativeElement.style.marginBottom = value + 50 + "px";
      }
    });
     */
    this.keyboard.didHide.subscribe({
      next: () => {
        console.log(0 + '关闭');
        this.checkBlur();
      }
    });
  }

 

Published 42 original articles · won praise 4 · Views 4614

Guess you like

Origin blog.csdn.net/lucasxt/article/details/103084900