我用Ionic 5/ angular制作的应用程序有问题。发生的情况是,当我将焦点放在一个输入上时,键盘抬起并覆盖所选的输入。有没有办法避免这种行为,让它自动滚动,直到键盘定位在选定的输入下方?
发布于 2020-12-01 14:46:03
如果您使用的是cordova,您可以设置当出现软键盘('adjustResize‘或'adjustPan')时如何处理UI。
为此,在config.xml,内部,在<platform name="android">中添加一个<edit-config>标记
<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="merge">
<activity android:windowSoftInputMode="adjustPan" />
</edit-config>请确保在<widget>标签中添加android-res命名空间:
<widget xmlns:android="http://schemas.android.com/apk/res/android" .....>适用于电容器应用的:
当键盘出现时,使用键盘接口的setResizeMode()方法来调整UI。
在app.component.ts中:
import { Plugins, KeyboardInfo } from '@capacitor/core';
const { Keyboard } = Plugins;
...
Keyboard.setResizeMode({mode:'ionic'});有关其他支持的模式,请查看https://capacitorjs.com/docs/apis/keyboard#keyboard-configuration-ios-only
发布于 2020-12-01 16:16:11
你可以简单地在你的页面中使用“边距”。
如果您希望仅使用[style.margin-bottom]="onFocus?'20rem':null"并在(焦点)/(模糊)中的每个输入中设置边距,请将属性onFocus更改为true/false。为了让这个“简单”,你可以使用一个指令,这个指令是make a next of a service,在main组件中你可以订阅这个主题。好吧,在代码中:
服务:
@Injectable({
providedIn: 'root',
})
export class AuxService {
focusSubject:Subject<boolean>=new Subject<boolean>()
constructor() { }
}该指令:(参见该指令的“选择器”,应用于所有输入否则复选框)
@Directive({
selector: 'input:not([type="checkbox])'
})
export class OnFocusDirective {
@HostListener('focus')
_() {
this.auxService.focusSubject.next(true)
}
@HostListener('blur')
__() {
this.auxService.focusSubject.next(false)
}
constructor(private auxService:AuxService) { }
}main-component:
export class AppComponent{
onFocus$=this.auxService.focusSubject
constructor(private auxService:AuxService) { }
}及其.html
<div [style.margin-bottom]="(onFocus$|async)?'20rem':null">
<p>
Start editing to see some magic happen :)
</p>
<input>
</div>我想这应该行得通
https://stackoverflow.com/questions/65083169
复制相似问题