Flex 4.5 移动设备在软键盘激活事件上使用动画调整文本区域大小?

发布于 2024-11-17 21:50:06 字数 3830 浏览 2 评论 0原文

我使用 Flex 4.5.1 和 AIR 2.7(以及 Flash Builder 4.5.1)为 Blackberry Playbook 构建应用程序。

该应用程序有一个很大的文本区域,当软键盘显示时需要调整其大小。我能够连接到软键盘事件并在那里执行操作。

现在,我想在键盘显示时调整文本区域的大小以适合屏幕的其余部分。我知道当前和目标大小,并希望使用平滑的动画来显示文本区域的大小调整。 (我还无法设置高度,并且可以看到文本区域在键盘激活事件中正确调整大小 - 但我想通过动画来做到这一点)。我尝试过使用 Animate 类、spark.effects.Move 类,但在这种情况下它们似乎都不起作用。他们似乎运行动画,但屏幕没有刷新!

我不想在 ViewNavigatorApplication 上使用内置的 resizeAppForKeyboard 属性。我已在应用程序描述符中设置为“无”,因此该部分没问题。

有什么想法/想法吗?我的方法完全正确吗?如何在键盘激活事件中使用动画来调整文本区域的大小?我的代码如下所示:

在主视图中(onCreationComplete 事件):(txNote 是有问题的文本区域)

txNote.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, function(e:SoftKeyboardEvent):void {
    toggleEditMode(true);
});

txNote.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, function(e:SoftKeyboardEvent):void {
    toggleEditMode(false);
});

private function toggleEditMode(keyboardActivated:Boolean):void {
    trace("toggle edit: " + editMode + ", kb activating: " + keyboardActivated + ", txNote height = " + txNote.height);

    editMode = keyboardActivated;

    //we handle resize manually, because we want a nice animation happening and we want to resize only the text area - nothing else.
    var y:Number = editMode ? -38 : 0;
    var height:Number = editMode ? 218 : 455;
    txNote.moveAndSize(y, height);
}

txNote.moveAndSize 中的代码:

public function moveAndSize(newY:Number, newHeight:Number):void {

//parent group uses BasicLayout
//(this.parent as Group).autoLayout = false;
//resizePath.valueFrom = this.height;
//resizePath.valueTo = newHeight;

//movePath.valueFrom = this.y;
//movePath.valueTo = newY;

//resizeEffect.heightFrom = this.height;
//resizeEffect.heightTo = height;

    this.top = newY;
    moveEffect.xFrom = this.x;
    moveEffect.xTo = this.x;

    moveEffect.yFrom = this.y;
    moveEffect.yTo = newY;

    moveEffect.end();
    moveEffect.play([ this ]);

    //this.move(x, newY);
    //animate.play([ this ]);

    //this.height = height;
    //this.y = y;

    //setLayoutBoundsSize(width, height);
    //setLayoutBoundsPosition(x, y);
}

我尝试的 moveEffect / movePath / animate 各种内容在 txNote 构造函数中设置如下:

public class NotesArea extends TextArea {
//      private var animate:Animate;
//      private var movePath:SimpleMotionPath;
//      private var resizePath:SimpleMotionPath;

        private var moveEffect:Move;
//      private var resizeEffect:Resize;

        public function NotesArea() {
            super();

//          animate = new Animate();
//          var paths:Vector.<MotionPath> = new Vector.<MotionPath>();
//          movePath = new SimpleMotionPath("top");
//          resizePath = new SimpleMotionPath("height");
//          paths.push(movePath);
            //paths.push(resizePath);

//          animate.duration = 300;
//          animate.motionPaths = paths;

//          animate.addEventListener(EffectEvent.EFFECT_UPDATE, function(e:EffectEvent):void {
//              trace("y = " + y);
//              invalidateDisplayList();
//          });
//          animate.addEventListener(EffectEvent.EFFECT_END, function(e:EffectEvent):void {
//              trace("EFFECT ended: y = " + y);
//          });

            moveEffect = new Move();
            moveEffect.duration = 250;
            moveEffect.repeatCount = 1;
            moveEffect.addEventListener(EffectEvent.EFFECT_END, function (e:EffectEvent):void {
                //(this.parent as Group).autoLayout = true;
                trace("move effect ran. y = " + y + ", top = " + top);
            });

            //this.setStyle("moveEffect", moveEffect);
//
//          resizeEffect = new Resize();
//          resizeEffect.duration = 250;
//          this.setStyle("resizeEffect", resizeEffect);
        }

}

I'm using Flex 4.5.1 with AIR 2.7 (and Flash Builder 4.5.1) to build an app for the Blackberry Playbook.

The app has a large textarea that needs to be resized when the soft keyboard shows up. I am able to hook into the soft keyboard events and do things there.

Now, I want to resize the textarea to fit the remaining part of the screen when the keyboard shows up. I know the current and destination size and want to use a smooth animation to show the textarea resizing. (I can't already set the height and can see the textarea being correctly resized in the keyboard_activating event - but I want to do it through an animation). I've tried using the Animate class, the spark.effects.Move class and none of them seem to work in this case. They seem to run the animation but the screen does not get refreshed!

I don't want to use the built-in resizeAppForKeyboard property on the ViewNavigatorApplication. I have set to 'none' in the app descriptor so that part of it is fine.

Any ideas / thoughts? Is my approach correct at all? How would one go about resizing the textarea using an animation in the keyboard activating event? My code looks like:

In the main view (onCreationComplete event): (txNote is the textarea in question)

txNote.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, function(e:SoftKeyboardEvent):void {
    toggleEditMode(true);
});

txNote.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, function(e:SoftKeyboardEvent):void {
    toggleEditMode(false);
});

private function toggleEditMode(keyboardActivated:Boolean):void {
    trace("toggle edit: " + editMode + ", kb activating: " + keyboardActivated + ", txNote height = " + txNote.height);

    editMode = keyboardActivated;

    //we handle resize manually, because we want a nice animation happening and we want to resize only the text area - nothing else.
    var y:Number = editMode ? -38 : 0;
    var height:Number = editMode ? 218 : 455;
    txNote.moveAndSize(y, height);
}

The code in txNote.moveAndSize:

public function moveAndSize(newY:Number, newHeight:Number):void {

//parent group uses BasicLayout
//(this.parent as Group).autoLayout = false;
//resizePath.valueFrom = this.height;
//resizePath.valueTo = newHeight;

//movePath.valueFrom = this.y;
//movePath.valueTo = newY;

//resizeEffect.heightFrom = this.height;
//resizeEffect.heightTo = height;

    this.top = newY;
    moveEffect.xFrom = this.x;
    moveEffect.xTo = this.x;

    moveEffect.yFrom = this.y;
    moveEffect.yTo = newY;

    moveEffect.end();
    moveEffect.play([ this ]);

    //this.move(x, newY);
    //animate.play([ this ]);

    //this.height = height;
    //this.y = y;

    //setLayoutBoundsSize(width, height);
    //setLayoutBoundsPosition(x, y);
}

The moveEffect / movePath / animate various things I tried are set up in the txNote constructor as follows:

public class NotesArea extends TextArea {
//      private var animate:Animate;
//      private var movePath:SimpleMotionPath;
//      private var resizePath:SimpleMotionPath;

        private var moveEffect:Move;
//      private var resizeEffect:Resize;

        public function NotesArea() {
            super();

//          animate = new Animate();
//          var paths:Vector.<MotionPath> = new Vector.<MotionPath>();
//          movePath = new SimpleMotionPath("top");
//          resizePath = new SimpleMotionPath("height");
//          paths.push(movePath);
            //paths.push(resizePath);

//          animate.duration = 300;
//          animate.motionPaths = paths;

//          animate.addEventListener(EffectEvent.EFFECT_UPDATE, function(e:EffectEvent):void {
//              trace("y = " + y);
//              invalidateDisplayList();
//          });
//          animate.addEventListener(EffectEvent.EFFECT_END, function(e:EffectEvent):void {
//              trace("EFFECT ended: y = " + y);
//          });

            moveEffect = new Move();
            moveEffect.duration = 250;
            moveEffect.repeatCount = 1;
            moveEffect.addEventListener(EffectEvent.EFFECT_END, function (e:EffectEvent):void {
                //(this.parent as Group).autoLayout = true;
                trace("move effect ran. y = " + y + ", top = " + top);
            });

            //this.setStyle("moveEffect", moveEffect);
//
//          resizeEffect = new Resize();
//          resizeEffect.duration = 250;
//          this.setStyle("resizeEffect", resizeEffect);
        }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-11-24 21:50:06
yourTextField.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, onActivating);
yourTextField.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATING, onActivating); 
yourTextField.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, onActivating); 

// in the event listener to the textField IE : 

private function onActivating(event:SoftKeyboardEvent):void 
{
  //listen to the event; make your move here.
}
yourTextField.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_DEACTIVATE, onActivating);
yourTextField.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATING, onActivating); 
yourTextField.addEventListener(SoftKeyboardEvent.SOFT_KEYBOARD_ACTIVATE, onActivating); 

// in the event listener to the textField IE : 

private function onActivating(event:SoftKeyboardEvent):void 
{
  //listen to the event; make your move here.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文