有没有人知道在新版本的flex中是否有任何类型的长按手势(如在Android上)?
我希望长按时列表中的项目可编辑/删除,但我真的希望我不会用计时器和诸如此类的东西制作我自己的长按手势。
如果没有内置,有没有人知道有关如何制作长按手势的任何资源/博客文章 - 或者,还有如何制作可编辑列表?
答案 0 :(得分:2)
private var deleteAlert:DeleteAlert = new DeleteAlert();
private var longPressTimer:Timer = new Timer(1500,1);
protected function LoadChartView_viewActivateHandler(event:ViewNavigatorEvent):void {
enableClick();
}
private function startLongPressMouse(event:MouseEvent):void {
startLongPressTimer();
list.addEventListener(MouseEvent.MOUSE_MOVE, endLongPressMouse);
}
private function endLongPressMouse(event:MouseEvent):void {
stopLongPressTimer();
enableClick();
list.removeEventListener(MouseEvent.MOUSE_MOVE, endLongPressMouse);
}
private function startLongPress(event:TouchEvent):void {
startLongPressTimer();
list.addEventListener(TouchEvent.TOUCH_MOVE, endLongPress);
}
private function endLongPress(event:TouchEvent):void {
stopLongPressTimer();
enableClick();
list.removeEventListener(TouchEvent.TOUCH_MOVE, endLongPress);
}
private function startLongPressTimer():void {
longPressTimer.start();
longPressTimer.addEventListener(TimerEvent.TIMER_COMPLETE, longPressHandler);
}
protected function disableClick():void {
trace("disable click");
list.removeEventListener(MouseEvent.CLICK, regularClickHander);
}
public function enableClick():void {
list.callLater(list.addEventListener, [MouseEvent.CLICK, regularClickHander]);
}
public function resetListSelection():void {
list.selectedIndex = -1;
list.validateDisplayList();
}
private function stopLongPressTimer():void{
longPressTimer.stop();
longPressTimer.reset()
}
public function longPressHandler(event:TimerEvent):void{
disableClick();
stopLongPressTimer();
deleteAlert.addEventListener(PopUpEvent.CLOSE, popupClosedHandler);
deleteAlert.open(this, false);
PopUpManager.centerPopUp(deleteAlert);
}
public function popupClosedHandler(event:PopUpEvent):void{
if (event.commit)data.removeItemAt(list.selectedIndex);
callLater(resetListSelection);
}
我使用鼠标和触摸事件进行简单测试:
<s:List id="list" top="0" bottom="0" left="0" right="0"
dataProvider="{data}"
touchBegin="startLongPress(event)" touchEnd="endLongPress(event)"
mouseDown="startLongPressMouse(event)" mouseUp="endLongPressMouse(event)">
答案 1 :(得分:0)
答案 2 :(得分:0)
查看Gestouch(开发分支是最新的) org.gestouch.gestures.LongPressGesture