【问题标题】:How to do a transition effect on state change with Apache Royale?如何使用 Apache Royale 对状态变化产生过渡效果?
【发布时间】:2019-09-26 18:16:50
【问题描述】:

我想在改变状态时有一个过渡动画。

经过几次尝试,我看不出有什么问题。 我的第一个目标是在隐藏“Card HOME”时触发从 1 到 0 的 alpha 效果

由于没有 showEffecthideEffect,我尝试使用 transitions 属性

(update:看SDK源码,我想我需要添加StatesWithTransitionsImpl,所以我更新了我的代码,但是当点击“Description”时,“home card”没有过渡,它会淡出,但不起作用)

<?xml version="1.0" encoding="utf-8"?>

<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:js="library://ns.apache.org/royale/basic" 
                xmlns="*"
                pageTitle="RoyaleStore">

    <fx:Script>
        <![CDATA[   
            import org.apache.royale.core.ValuesManager;


            private function headHome():void
            {
                    initialView.currentState = "HomeState";
            }

            private function headToProducts():void
            {
                    initialView.currentState = "ProductState";                    
            }



        ]]>
    </fx:Script>

    <fx:Style source="main.css"/>

    <js:valuesImpl>
        <js:SimpleCSSValuesImpl />
    </js:valuesImpl>
    <js:beads>
        <js:ApplicationDataBinding />
    </js:beads>

    <js:initialView>
        <js:View >

            <js:beads>
                <js:VerticalLayout />
                <!-- if you comment out this section and comment <fx:Style source="main.css"/> then it isn't working -->
                    <!--  <core:StatesWithTransitionsImpl/>
                    <utils:EffectTimer/>-->
            </js:beads>

            <js:states>
                <js:State name="HomeState"  />
                <js:State name="ProductState"  />
            </js:states>

            <js:transitions>
                <js:Transition fromState="HomeState" toState="*">
                    <js:Fade target="homeView" alphaFrom="1" alphaTo="0" duration="1000" />
                </js:Transition>
                <js:Transition fromState="*" toState="HomeState">
                     <js:Fade target="homeView" alphaFrom="0" alphaTo="1" duration="1000" />
                </js:Transition>
                <js:Transition fromState="ProductState" toState="*">
                    <js:Fade target="productView" alphaFrom="1" alphaTo="0" duration="1000" />
                </js:Transition>
                <js:Transition fromState="*" toState="ProductState">
                    <js:Fade target="productView" alphaFrom="0" alphaTo="1" duration="1000" />
                </js:Transition>
            </js:transitions>


            <js:Group>
                <js:beads>
                    <js:HorizontalLayout />
                </js:beads>
                <js:TextButton text="Home" click="headHome()" />
                <js:TextButton text="Products" click="headToProducts()"/>
            </js:Group>

            <js:Group>
                 <js:Label id="productView" text="productView" includeIn="ProductState"  />
                 <js:Label id="homeView" text="homeView" includeIn="HomeState" />
            </js:Group>

        </js:View>        
    </js:initialView>    
</js:Application>

它是如何工作的?

(更新 2 :我已经使用 Royale Store 示例的一部分更新了代码。单击“主页”时它可以工作,但奇怪的是 单击“产品”时却没有 strong>. Bug 与否?)

我发现你必须在 main.css 中包含:

@namespace basic "library://ns.apache.org/royale/basic";

global {
    IStatesImpl:            ClassReference("org.apache.royale.core.StatesWithTransitionsImpl");
    IEffectTimer:           ClassReference("org.apache.royale.utils.EffectTimer");
}

另一个问题是,如果我尝试像这样添加珠子:

 <js:beads>
       <core:StatesWithTransitionsImpl/>
       <utils:EffectTimer/>
 </js:beads>

(并删除包括 main.css)然后它不起作用...

问候

【问题讨论】:

    标签: animation state effects apache-royale


    【解决方案1】:

    结帐示例/royale/RoyaleStore。它正在使用状态转换。

    【讨论】:

    • 谢谢,实际上,它帮助了我,现在它工作了一半......试图简化代码,我问自己是否有错误。我已经更新了问题中的代码
    • 关于在 CSS 中使用 StatesWithTransitionsImpl 与在 js:beads 列表中(在一条链上):在 js:beads 中应用的珠子就像通过样式属性添加到 HTMLElement 的样式。它们仅在您应用它们的实例中可见,而在 CSS 中任何 HTMLElement 都可以查找适当的样式。各种容器将在 js:beads 上然后在 CSS 中查找 IStatesImpl。如果您仅将 IStatesImpl 应用于特定实例,则其他实例将看不到它。
    猜你喜欢
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 2020-09-23
    • 2013-05-24
    相关资源
    最近更新 更多