我刚接触ionic,正在设计一个登录页面,但是我注意到当我将应用程序部署到ios设备上时,当点击/按下输入字段时,原生ios键盘会将内容向上推。
我一直在想如何解决这个问题,但一直没有运气,我目前使用的是最新的离子框架。
是否有方法可以确保内容不会被推高?
下面是我的登录html:
<ion-content class="background" [fullscreen]="true" slot="fixed">
<h1 class="login-title-text">ign you in</h1>
<p class="login-subtitle-text">Welcome back!</p>
<div class="inputs">
<ion-input class="item-input" type="email" placeholder="Email"></ion-input>
<ion-input class="item-input" type="password" placeholder="Password"></ion-input>
</div>
</ion-content>
<ion-footer>
<ion-button color="dark" expand="block">Login</ion-button>
<ion-button color="dark" expand="block">Forgot Password</ion-button>
<ion-button color="dark" expand="block">Register</ion-button>
</ion-footer>
下面是我的scss:
ion-content {
--keyboard-offset: 0px;
}
.background {
--background: url("/assets/img/background.jpg") no-repeat fixed center;
}
.login-title-text {
font-weight: bold;
font-size: 28px;
padding: 50px 0 20px 30px;
}
.login-subtitle-text {
font-size: 18px;
padding: 10px 0 20px 30px;
}
.inputs {
padding: 30px;
}
.item-input {
border: 1px solid grey;
border-radius: 10px;
height: 50px;
text-indent: 10px;
margin-bottom: 20px;
}
ion-footer {
padding: 30px;
ion-button {
margin-bottom: 20px;
}
}
2条答案
按热度按时间jchrr9hc1#
I finally fixed this issue. I installed the capacitor keyboard package.
then navigated to root dir project where the package.json is and ran this command:
added this in capacitor.config.ts inside the CapacitorConfig object
then I ran
might be best to restart simulators after you have done this.
7dl7o3gd2#
You need to import the keyboard package into your
.ts
fileimport { Keyboard } from '@ionic-native/keyboard/ngx';
Then you need to add an event to your input element
(onShown)="hideKey()"
<-- it depend on the input element, this eg., is taken from calendar control onShowBelow is the code to hide the keyboard
I hope this solution will help you
Thanks.