【问题标题】:Nativescript Gesture- Rotation strange behaviorNativescript Gesture-旋转奇怪的行为
【发布时间】:2019-06-16 17:40:06
【问题描述】:

我正在使用 Nativescript Vue 并尝试通过 Nativescript-Gesture Rotation 旋转 TextView 标记中的文本。文字会旋转,但不流畅,会从一个方向跳到另一个方向。这就是我的问题

为什么会这样? NS-Gesture Rotation 表现如此奇怪的原因是什么?以及如何让它发挥作用?

我将在此处和NS Playground 中发布我的示例示例。

<template>
    <Page class="page">
        <ActionBar title="Home" class="action-bar" />
            <StackLayout class="home-panel">
                <TextView @rotation="onRotation" id="liveLabel" textWrap="true"
                    :rotate="textRotation" editable="false">
                    <FormattedString id="formString">
                        <Span id="spanText" text="Test text" fontSize="20"
                            color="red" />
                    </FormattedString>
                </TextView>
            </StackLayout>
    </Page>
</template>

<script>
    export default {
        data() {
            return {
                textRotation: 0
            };
        },
        methods: {
            onRotation(args) {
                console.log(
                    "Rotate angle: " + args.rotation + " state: " + args.state
                );
                this.textRotation = Math.floor(args.rotation);
            }
        }
    };
</script>

【问题讨论】:

    标签: nativescript nativescript-vue


    【解决方案1】:

    实际上,您所看到的完全是意料之中的,您正在实现它。

    假设您正在计算对象的位置并同时移动它,因此 TextView 上的旋转事件会根据您的手指移动一次给出正确的位置,然后根据您应用的新旋转值给出另一个位置文本视图。

    为了解决这个问题,您应该有 2 个对象副本(此处为 TextView)。一个用于监听手指动作,另一个用于制作动画,类似这样。

    <template>
        <Page class="page">
            <ActionBar title="Home" class="action-bar" />
            <StackLayout class="home-panel">
                <GridLayout>
                    <TextView ref="animatedLbl" textWrap="true" :rotate="textRotation"
                        editable="false" visibility="hidden" verticalAlignment="top">
                        <FormattedString>
                            <Span text="Test text" fontSize="20" color="red" />
                        </FormattedString>
                    </TextView>
                    <TextView ref="hostLbl" @rotation="onRotation" textWrap="true"
                        editable="false" verticalAlignment="top">
                        <FormattedString>
                            <Span text="Test text" fontSize="20" color="red" />
                        </FormattedString>
                    </TextView>
                </GridLayout>
            </StackLayout>
        </Page>
    </template>
    
    <script>
        import * as GestureModule from "tns-core-modules/ui/gestures";
        export default {
            data() {
                return {
                    textRotation: 0
                };
            },
            methods: {
                onRotation(args) {
                    if (args.state === GestureModule.GestureStateTypes.began) {
                        this.$refs.hostLbl.nativeView.visibility = "hidden";
                        this.$refs.animatedLbl.nativeView.visibility = "visible";
                    }
                    this.textRotation = Math.floor(args.rotation);
                    if (
                        args.state === GestureModule.GestureStateTypes.cancelled ||
                        args.state === GestureModule.GestureStateTypes.ended
                    ) {
                        this.$refs.hostLbl.nativeView.rotate = this.textRotation;
                        this.$refs.hostLbl.nativeView.visibility = "visible";
                        this.$refs.animatedLbl.nativeView.visibility = "hidden";
                    }
                }
            }
        };
    </script>
    

    Playground Sample

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-06
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多