在iOS 7 Safari中,如何通过边缘滑动与后退/前进按钮区分popstate事件? [英] In iOS 7 Safari, how do you differentiate popstate events via edge swipe vs. the back/fwd buttons?

查看:488
本文介绍了在iOS 7 Safari中,如何通过边缘滑动与后退/前进按钮区分popstate事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 7 Safari中,现在有两种向前/向后导航的方法 - 使用底部的传统后退/前进按钮箭头或从屏幕边缘滑动。我正在使用动画在我的ajax应用程序中的页面之间进行转换,但如果用户通过边缘滑动导航,我不想触发该转换,因为这是一个动画本身。

In iOS 7 Safari there are now two ways to navigate back/forward -- using the traditional back/forward button arrows at the bottom or by swiping from the edge of the screen. I'm using an animation to transition between pages in my ajax app, but I don't want to fire that transition if users are navigating via the edge swipe, because that is an animation itself.

但是,两种导航类型的popstate事件对象看起来都是相同的 - 有没有办法区分这两种类型的用户导航,以便我们可以做出相应的响应?

However, the popstate event objects appear to be identical for both types of navigation -- is there any way to differentiate between these two types of user navigations so we can respond accordingly?

更新:我能够使用(似乎是)iOS7 Safari中的错误来正确检测边缘滑动与后退按钮点击。问题在于,当使用边缘滑动(但是touchstart和touchmove)时,触摸事件不会被触发(直到下一个触摸事件)。所以我设置了一个 shouldAnimate 标志并在touchmove上禁用它 - 然后如果标志被禁用并且popstate发生,我知道它是边缘滑动。

UPDATE: I was able to use (what appears to be) a bug in iOS7 Safari to detect correctly the edge swipe vs. back button tap. The bug is that the touchend event is not triggered (until the next touch event) when using the edge swipe (but touchstart and touchmove are). So I set a shouldAnimate flag and disable it on touchmove -- then if the flag is disabled and the popstate occurs, I know it's an edge swipe.

99%的时间是正确的 - 唯一可能发生故障的时间是用户边缘部分滑动然后让我们离开并让当前页面快速恢复到位(此时我的标志仍然会被禁用)然后点击后退按钮(不触发任何触摸事件)。为了处理最后[边缘]的情况,我在touchmove上设置了一个定时器,在50ms后重新启用该标志。

It's correct 99% of the time -- the only time where it could potentially fail is when a user edge-swipes partially and but then lets go and lets the current page snap back into place (at which point my flag would still be disabled) and then taps the back button (which fires no touch events). To handle that last [edge] case I set a timer on touchmove to re-enable the flag after 50ms.

是的它是脏但是现在它让我得到了什么我几乎在所有情况下都想要它,所以我很好用它 - 直到Apple修复了这个bug,但希望它们还能在popstate事件对象中提供一个指示器,告诉我们它是什么类型的导航。

Yes it's "dirty" but for now it gets me what I want in almost every case so I'm ok with it -- until Apple fixes the bug, but hopefully they'll also provide an indicator in the popstate event object that tells us what kind of navigation it is.

推荐答案

简短而悲伤的答案:不会。这种后退/前进滑动不会传播到实际页面,而是发生在操作系统级别。

Short and sad answer: No. This back/forward-swipes are not propagated to the actual page but happen on an OS-level.

这篇关于在iOS 7 Safari中,如何通过边缘滑动与后退/前进按钮区分popstate事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆