Angular 当键盘显示时,爱奥尼亚2型上升

Angular 当键盘显示时,爱奥尼亚2型上升,angular,typescript,ionic-framework,ionic2,ionic3,Angular,Typescript,Ionic Framework,Ionic2,Ionic3,我正在使用最新版本的离子2。 我的代码有一个,里面有一个文本输入。当我试图在Android上输入一些东西时,整个页面都会被键盘向上推 html文件 <ion-content class="login-screen" padding> <form (ngSubmit)="login()" novalidate> <ion-list> <ion-item> <ion-label fixed>Usern

我正在使用最新版本的离子2。 我的代码有一个
,里面有一个文本输入。当我试图在Android上输入一些东西时,整个页面都会被键盘向上推

html文件

<ion-content class="login-screen" padding>
  <form (ngSubmit)="login()" novalidate>
    <ion-list>
      <ion-item>
        <ion-label fixed>Username</ion-label>
        <ion-input type="text" name="username" [(ngModel)]="username" required></ion-input>
      </ion-item>
      <ion-item>
        <ion-label fixed>Password</ion-label>
        <ion-input type="password" name="password" [(ngModel)]="password" required></ion-input>
      </ion-item>
    </ion-list>
    <button ion-button full type="submit">Login</button>
  </form>
  <button ion-button clear full outline type="button" (click)="openModal()">Forgot Password?</button>
</ion-content>

用户名
密码
登录
忘记密码了?

有什么解决方案吗?

有一些关于滚动的输入和表单的问题,如前所述,因此我建议等待下一个RC来解决,因为这不是你的代码错误,只是离子错误。

这一切都应该在RC4中解决(很快)。也就是说,要在聚焦输入时禁用滚动,请将其添加到配置对象(在
@NgModule
中):

关于这两个属性,可以找到一个很好的解释:

但是,在Ionic2默认设置下,还有其他功能 试图通过添加 填充到内容的底部(“scrollAssist”),并保持 通过滚动返回视口中的聚焦输入元素 ('autoFocusAssist')。scrollAssist和autoFocusAssist都具有良好的性能 在配置中实现的开关似乎没有 公共文件尚未记录

您还可以使用
爱奥尼亚插件键盘
阻止本机浏览器向上推/滚动内容窗格,并允许键盘滑动并覆盖现有内容:

this.platform.ready().then(() => {
    StatusBar.styleDefault();
    Splashscreen.hide();

    Keyboard.disableScroll(false); // <- like this

    // ...

通过保持
scrollAssist:true
我们可以避免键盘在接近页面底部时隐藏的输入,通过设置
scrollPadding:false
我们还可以避免隐藏键盘后出现一些与空白相关的奇怪错误。

将此方法添加到此页面的.ts中

ionViewWillEnter() {
  this.content.resize();
}

我的场景是:在这个页面上调用键盘,但是当你返回到上一个页面时,页面将作为一个整体出现,我尝试用这个方法解决这个问题,我使用ionic2。

只需在app.module.ts中将这个属性添加到你的ionicModule中。对我有用

IonicModule.forRoot(MyApp, {
      scrollAssist: false, 
      autoFocusAssist: false
    })

从Ionic项目的iOS平台打开iOS工作区,并在MainViewController.m中写入以下方法

/////////////--------------------------//////////////
/*
 *Description: this method was trigger by selector keyboarwillhide from notification
 */
-(void)keyboardWillHide
{
    if (@available(iOS 12.0, *)) {
        WKWebView *webview = (WKWebView*)self.webView;
         for(UIView* v in webview.subviews){
            if([v isKindOfClass:NSClassFromString(@"WKScrollView")]){
                UIScrollView *scrollView = (UIScrollView*)v;
                [scrollView setContentOffset:CGPointMake(0, 0)];
             }
          }
     }
}
通过NotificationCenter在viewDidLoad中调用上述方法

- (void)viewDidLoad
{
    [super viewDidLoad];

    /**
     * observer notification when keyboard will hide
     */

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}

但我认为有一些方法可以在以输入为中心时禁用滚动。但我不知道它是如何修复的。注意:Keyboard.disableScroll(),ios和windows支持Hanks@Luckylooke,我已经在答案中添加了这一信息:)如果页面有多个输入字段和页脚上有一个按钮,上述解决方案会起作用吗?@Sebafereras,问题仍然存在,请解决它,使用了
top
和一些其他属性,我删除了这些属性,并且工作正常
/////////////--------------------------//////////////
/*
 *Description: this method was trigger by selector keyboarwillhide from notification
 */
-(void)keyboardWillHide
{
    if (@available(iOS 12.0, *)) {
        WKWebView *webview = (WKWebView*)self.webView;
         for(UIView* v in webview.subviews){
            if([v isKindOfClass:NSClassFromString(@"WKScrollView")]){
                UIScrollView *scrollView = (UIScrollView*)v;
                [scrollView setContentOffset:CGPointMake(0, 0)];
             }
          }
     }
}
- (void)viewDidLoad
{
    [super viewDidLoad];

    /**
     * observer notification when keyboard will hide
     */

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillHide)
                                                 name:UIKeyboardWillHideNotification
                                               object:nil];
}