看起来 Josh Tynjala 正在寻求将此功能添加到 Feathers:https ://github.com/joshtynjala/feathers/issues/527
与此同时,我也想要同样的东西,所以我只是把它搞定了,我很乐意分享它(警告:尚未经过广泛测试):
package com.hiddenachievement.space.components
{
import feathers.core.FeathersControl;
import starling.animation.Transitions;
import starling.animation.Tween;
import starling.core.Starling;
import starling.display.Sprite;
/**
* Creates a control that emerges from one side of the stage, while moving the main view to show it.
*/
public class EdgeSlideControl extends FeathersControl
{
private var _mainView:Sprite;
private var _open:Boolean;
protected var _tween:Tween;
protected var _side:int;
protected var _callback:Function;
protected var _uncover:Boolean;
static public const NORTH:int = 0;
static public const SOUTH:int = 1;
static public const EAST:int = 2;
static public const WEST:int = 3;
/**
* Creates an EdgeSlideControl.
*
* @param mainView The main view (possibly a ScreenNavigator) that will move to show the menu.
* @param side The side that the control will emerge from.
* @param uncover When true, the main view will slide away to uncover the control. When false, the control will slide in from the side, as the main view slides out of the way.
*
*/
public function EdgeSlideControl(mainView:Sprite, side:int, uncover:Boolean = true)
{
super();
_mainView = mainView;
_side = side;
_uncover = uncover;
}
/**
* Implements the standard FeathersControl's initialize.
*/
override protected function initialize():void
{
_open = false;
visible = false;
}
/**
* Begin the animation to display the control.
*/
public function show(callback:Function=null):void
{
_callback = callback;
_tween = new Tween(_mainView, 0.2, Transitions.LINEAR);
_tween.onUpdate = updateSlide;
_tween.onComplete = slideComplete;
switch(_side)
{
case NORTH:
_tween.animate("y", height);
break;
case SOUTH:
_tween.animate("y", -width);
break;
case EAST:
_tween.animate("x", -height);
break;
case WEST:
_tween.animate("x", width);
break;
}
Starling.juggler.add(_tween);
_open = true;
visible = true;
}
/**
* Begin the animation to hide the control.
*/
public function hide(callback:Function=null):void
{
_callback = callback;
_tween = new Tween(_mainView, 0.2, Transitions.LINEAR);
_tween.onUpdate = updateSlide;
_tween.onComplete = slideComplete;
switch(_side)
{
case NORTH:
case SOUTH:
_tween.animate("y", 0);
break;
case EAST:
case WEST:
_tween.animate("x", 0);
break;
}
Starling.juggler.add(_tween);
_open = false;
}
/**
* If the control is moving (not in "uncover" mode), move the control into place, next to the main view.
*/
public function updateSlide():void
{
if (!_uncover)
{
switch(_side)
{
case NORTH:
y = _mainView.y - height;
break;
case SOUTH:
y = _mainView.height - _mainView.y;
break;
case EAST:
x = _mainView.width - _mainView.x;
break;
case WEST:
x = _mainView.x - width;
break;
}
}
}
/**
* Perform any actions needed after the transition is done animating.
*/
public function slideComplete():void
{
if (_callback != null)
{
_callback();
}
visible = _open;
}
public function get isOpen():Boolean
{
return _open;
}
}
}
如果组件变为零,您可能需要在滑动方向上向组件添加显式大小。否则,使用应该非常简单。如果您需要有关如何使用它的更多指导,请告诉我。