[英]Disable window offset when keyboard appears for ios app
當 ios 應用程序出現鍵盤時禁用 window 偏移
當 ios 應用程序出現鍵盤時,我想禁用 window 偏移。 對於 android 應用程序,這是通過AndroidManifest.xml
完成的:
<activity ... android:windowSoftInputMode="adjustResize">
當鍵盤出現時,組件不會從它們的位置移動。 ios 是否有可能獲得這種行為?
在評論中找到解決方案: iOS 使項目的窗口滾動成為可選https://bugreports.qt.io/browse/Q適用於 me8079UG/browse/Q
=========================
Adrian Eddy添加了評論 - 20 年 4 月 11 日 01:44 - 已編輯
我找到了一種適用於 QML 的解決方法。 想法是在 QQuickItem 上安裝一個事件過濾器,並使用 Qt::InputMethodQuery::ImCursorRectangle 偵聽 QEvent::InputMethodQuery。 然后我們將其值設置為空 QRectF 並且 Qt 將不再滾動視圖以顯示該文本字段。
在 C++ 中准備一個 class 並將其暴露給 QML:
class Api : public QObject {
Q_OBJECT
....
public:
Q_INVOKABLE void setupImEventFilter(QQuickItem *item) {
static thread_local ImFixer imf;
item->installEventFilter(&imf);
}
}
// main() 中的某處:
view.rootContext()->setContextProperty("api", new Api());
我們也需要實際的事件過濾器:
class ImFixer :
public QObject {
Q_OBJECT
protected:
bool eventFilter(QObject *obj, QEvent *event) override {
if (event->type() == QEvent::InputMethodQuery) {
QInputMethodQueryEvent *imEvt = static_cast<QInputMethodQueryEvent *>(event);
if (imEvt->queries() == Qt::InputMethodQuery::ImCursorRectangle) {
imEvt->setValue(Qt::InputMethodQuery::ImCursorRectangle, QRectF());
return true;
}
}
return QObject::eventFilter(obj, event);
}
};
最后在 QML 中添加:
TextField {
id: tf;
...
Component.onCompleted: api.setupImEventFilter(tf);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.