Перемещение элемента пользовательского интерфейса с помощью встроенного скрипта клавиатуры (IOS)

В моем приложении nativescript - у меня есть кнопка внизу экрана. На экране есть текстовая область. Когда пользователь касается текстовой области, появляется виртуальная клавиатура. На этом этапе я хочу, чтобы кнопка внизу переместилась вверх и появилась прямо над виртуальной клавиатурой. Любые предложения о том, как я могу добиться этого как на Android, так и на iOS?

Код

<GridLayout>
<ActionBar title="" backgroundColor="#f82462" top="0" left="0">
    <NavigationButton (tap)="goBack()"></NavigationButton>
</ActionBar>
<GridLayout rows="*, auto">
    <GridLayout row ='0' rows="auto *" columns="">
        <GridLayout row="0" rows="" columns="">
            <Button text="Top Button" (tap)="goNext()"></Button>                
        </GridLayout>
        <GridLayout row="1" backgroundColor="#f82462">
            <TextView [(ngModel)]="xyz" class="input" hint="Write your question as a complete sentence.Click on camera to add images if required." returnkeyType="done" id="questionText"></TextView>
        </GridLayout>
</GridLayout>
<StackLayout row='1'>
    <Button text="Next" (tap)="goNext()"></Button>
</StackLayout>
</GridLayout>


person Anurag    schedule 22.03.2017    source источник
comment
В таких ситуациях я обычно добавляю кнопку справа от навигационной панели. Кстати, вы пробовали npmjs.com/package/nativescript-iqkeyboardmanager?   -  person Eddy Verbruggen    schedule 22.03.2017
comment
Спасибо за ответ @EddyVerbruggen. В моем пользовательском интерфейсе у меня есть панель поиска внутри панели действий, и я не могу разместить там что-либо еще. Для IOS у меня установлена ​​iqkeyboard, но, к сожалению, она не помогает мне в достижении моей цели по перемещению кнопки в верхнюю часть клавиатуры, когда она появляется.   -  person Anurag    schedule 22.03.2017


Ответы (2)


Я не могу проверить это прямо сейчас, но вы пытались обернуть все внутри основного GridLayout в <ScrollView> ... </ScrollView>

person nbo    schedule 30.03.2017
comment
это сработало для меня. По крайней мере, в Android. Никогда не тестировался на iOS - person Doua Beri; 30.12.2017

Я также столкнулся с этой проблемой для своего приложения для мгновенного чата, вот решение: https://gist.github.com/elvticc/0c789d08d57b1f4d9273f7d93a7083ec

// Also use IQKeyboardManager to customize the iOS keyboard
// See https://github.com/tjvantoll/nativescript-IQKeyboardManager

// let iqKeyboard: IQKeyboardManager = IQKeyboardManager.sharedManager();
// iqKeyboard.toolbarDoneBarButtonItemText             = "OK";
// iqKeyboard.canAdjustAdditionalSafeAreaInsets        = true;
// iqKeyboard.shouldFixInteractivePopGestureRecognizer = true;

// Angular
[...]
import { OnInit, OnDestroy, ElementRef, ViewChild } from "@angular/core";
[...]

// NativeScript
[...]
import { ios as iosApp } from "tns-core-modules/application/application";
[...]

@ViewChild("element") private _element: ElementRef<StackLayout>; // FlexboxLayout, GridLayout, etc.

private _keyboardHeight: number = 0;
private _elementHeight:  number = 0;
private _observerIDs:    Array<object> = new Array();

// Start events when the component is ready
ngOnInit(): void {

    // iOS keyboard events
    if (iosApp) {

        let eventNames: Array<string> = [
                UIKeyboardWillShowNotification,
                UIKeyboardDidShowNotification,
                UIKeyboardWillHideNotification
            ];

        // Catch the keyboard height before it appears
        this._observerIDs.push({
            event: eventNames[0],
            id: iosApp.addNotificationObserver(eventNames[0], (event) => {

                    let currHeight: number = this._keyboardHeight,
                        newHeight:  number = event.userInfo.valueForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue.size.height;

                    if (currHeight != newHeight) {

                        this._keyboardHeight = newHeight;

                    }

                })
        });

        // Position the element according to the height of the keyboard
        this._observerIDs.push({
            event: eventNames[1],
            id: iosApp.addNotificationObserver(eventNames[1], (event) => {

                    if (this._elementHeight == 0) {

                        this._elementHeight = this._element.nativeElement.getActualSize().height;

                    }

                    this._element.nativeElement.height = this._keyboardHeight + this._elementHeight;

                })
        });

        // Reposition the element according to its starting height
        this._observerIDs.push({
            event: eventNames[2],
            id: iosApp.addNotificationObserver(eventNames[2], () => {

                    this._element.nativeElement.height = this._elementHeight; // or "auto";

                })
        });

    }

}

// Stop events to avoid a memory leak
ngOnDestroy(): void {

    if (iosApp) {

        let index: number = 0;

        for (index; index < this._observerIDs.length; index++) {

            let observerId: number = this._observerIDs[index]['id'],
                eventName:  string = this._observerIDs[index]['event'];

            iosApp.removeNotificationObserver(observerId, eventName);

        }

    }

}

Оригинал Марселя Плоха: https://gist.github.com/marcel-ploch/bf914d0c5c65049e / >

person bgrand-ch    schedule 07.06.2019