FGUI的触碰事件

滑动手势事件,可以通过OnBegin+OnMove+OnEnd来关心滑动的结果,也可以通过OnAction来得到结果,结果有角度和方向

SwipeGesture gesture1 = new SwipeGesture(holder);

gesture1.onMove.Add(OnSwipeMove);

gesture1.onEnd.Add(OnSwipeEnd);

 

void OnSwipeMove(EventContext context)

{

SwipeGesture gesture = (SwipeGesture)context.sender;

Vector3 v = new Vector3();

if (Mathf.Abs(gesture.delta.x) > Mathf.Abs(gesture.delta.y))

{

v.y = -Mathf.Round(gesture.delta.x);

if (Mathf.Abs(v.y) < 2) //消除手抖的影响

return;

}

else

{

v.x = -Mathf.Round(gesture.delta.y);

if (Mathf.Abs(v.x) < 2)

return;

}

_ball.Rotate(v, Space.World);

}

void OnSwipeEnd(EventContext context)

{

SwipeGesture gesture = (SwipeGesture)context.sender;

Vector3 v = new Vector3();

if (Mathf.Abs(gesture.velocity.x) > Mathf.Abs(gesture.velocity.y))

{

v.y = -Mathf.Round(Mathf.Sign(gesture.velocity.x) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.x)));

if (Mathf.Abs(v.y) < 2)

return;

}

else

{

v.x = -Mathf.Round(Mathf.Sign(gesture.velocity.y) * Mathf.Sqrt(Mathf.Abs(gesture.velocity.y)));

if (Mathf.Abs(v.x) < 2)

return;

}

 

GTween.To(v, Vector3.zero, 0.3f).SetTarget(_ball).OnUpdate(

(GTweener tweener) =>

{

_ball.Rotate(tweener.deltaValue.vec3, Space.World);

});

}

 

长按手势,当按时一定时间后,通过OnAction来派发事件,如果once为false时,则间断N时间来派发OnAction;

LongPressGesture gesture2 = new LongPressGesture(holder);

gesture2.once = false;

gesture2.onAction.Add(OnHold);

 

void OnHold(EventContext context)

{

GTween.Shake(_ball.transform.localPosition, 0.05f, 0.5f).SetTarget(_ball).OnUpdate(

(GTweener tweener) =>

{

_ball.transform.localPosition = new Vector3(tweener.value.x, tweener.value.y, _ball.transform.localPosition.z);

});

}

两个手指的捏放操作

PinchGesture gesture3 = new PinchGesture(holder);

gesture3.onAction.Add(OnPinch);

 

void OnPinch(EventContext context)

{

GTween.Kill(_ball);

 

PinchGesture gesture = (PinchGesture)context.sender;

float newValue = Mathf.Clamp(_ball.localScale.x + gesture.delta, 0.3f, 2);

_ball.localScale = new Vector3(newValue, newValue, newValue);

}

手指反向操作

RotationGesture gesture4 = new RotationGesture(holder);

gesture4.onAction.Add(OnRotate);

void OnRotate(EventContext context)

{

GTween.Kill(_ball);

 

RotationGesture gesture = (RotationGesture)context.sender;

_ball.Rotate(Vector3.forward, -gesture.delta, Space.World);

}

在Vue中,可以使用`@touchstart`和`@touchmove`等事件来监听页面的事件。首先,在`mounted`钩子函数中调用`TouchMove`方法来设置监听事件。然后,在`methods`中编写对应的方法来处理事件。例如,可以使用`handleTouchStart`方法来记录开始时的Y轴数值,使用`handleTouchMove`方法来监听移动时的Y轴数值,并在超过一定距离后执行相应的操作,比如下拉刷新。这样就实现了在Vue中监听事件并实现下拉刷新的功能。 示例代码如下: ```javascript // 在mounted中调用TouchMove方法 mounted() { this.TouchMove(); }, // methods中编写事件的处理方法 methods: { TouchMove() { this.$refs.idealist.addEventListener('touchmove', this.handleTouchMove, false); this.$refs.idealist.addEventListener('touchstart', this.handleTouchStart, false); // 其他需要监听的事件 }, handleTouchStart(event) { // 处理开始的逻辑 }, handleTouchMove(event) { // 处理移动的逻辑 }, // 其他处理事件的方法 } ``` 以上代码中,`@touchmove`和`@touchstart`事件分别对应着`handleTouchMove`和`handleTouchStart`方法。你可以根据实际需求对这些方法进行修改和扩展,以实现你想要的事件处理逻辑。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [如何在vue中使用触摸事件](https://blog.csdn.net/oQingHeYiKan12/article/details/84228514)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [vue 中怎么监听屏幕事件](https://blog.csdn.net/weixin_49577940/article/details/123062116)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值