简体   繁体   English

禁用 IOS 13 safari 上的捏合缩放

[英]Disable pinch zoom on IOS 13 safari

I know this question has been asked so much.我知道这个问题被问了很多。 But have there been any updates on being able to disable pinch zoom on the latest version of safari?但是在最新版本的 safari 上是否有任何关于禁用捏合缩放的更新?

I have a map application that implements pinch to zoom on specific elements of the webpage (the map).我有一个 map 应用程序,它实现捏合以放大网页(地图)的特定元素。 I want users to be able to zoom in on the map, while the UI around the page stays the same.我希望用户能够放大 map,而页面周围的 UI 保持不变。 This has destroyed my users experience on IOS.这破坏了我在 IOS 上的用户体验。

Is there a way to at least disable pinch to zoom on specific elements?有没有办法至少禁用捏来放大特定元素?

Here is my webpage so you can see exactly what I'm talking about.这是我的网页,因此您可以确切地看到我在说什么。 I hope you can see why disabling viewport zoom (at least when the user pinches on the map) would actually be a benefit, for accessibility.我希望你能明白为什么禁用视口缩放(至少当用户在地图上捏捏时)实际上对可访问性有好处。

https://www.yapms.com/app/?t=USA_2020_presidential https://www.yapms.com/app/?t=USA_2020_presidential

more info: I'm using hammerjs to zoom in on specific elements on the webpage already, so I want to disable apples viewport zoom on those elements.更多信息:我已经在使用hammerjs 来放大网页上的特定元素,所以我想禁用这些元素的苹果视口缩放。

Maybe this event listener on the document will help也许文档上的这个事件监听器会有所帮助

document.addEventListener('touchmove', function (event) {
  if (event.scale !== 1) { event.preventDefault(); }
}, { passive: false });

Resource: disable viewport zooming iOS 10+ safari?资源: 禁用视口缩放 iOS 10+ safari?

Please see Casper Fabricius answer for detailed elaboration about this有关此问题的详细说明,请参阅 Casper Fabricius 的回答

None, of the JavaScript solutions worked for me.没有,JavaScript 解决方案对我有用。 What I did to fix the issue on IOS was to add the following CSS to each element that I wanted to prevent the default zoom action on.我为解决 IOS 上的问题所做的是将以下 CSS 添加到我想阻止默认缩放操作的每个元素中。

touch-action: none;

I think the most likely use case for apps built with web tech will be that you do not want the user to manually pinch zoom, but you still need them to scroll in the Y co-ordinate.我认为使用 web 技术构建的应用程序最可能的用例是您不希望用户手动捏缩放,但您仍然需要它们在 Y 坐标中滚动。 You can enable this on the whole app by targeting the html tag in css.您可以通过定位 css 中的 html 标签在整个应用程序上启用此功能。 Disabling pinch zoom is necessary for web based "apps" to behave like "apps".禁用缩放缩放对于基于 web 的“应用程序”的行为类似于“应用程序”是必要的。 Accessibility can be accommodated in different ways, such as offering preferences to adjust text sizes.可以通过不同的方式来适应可访问性,例如提供调整文本大小的首选项。 I tested this on Safari and Edge on iPhoneX OS ver 13.5.1我在 iPhoneX OS 13.5.1 版的 Safari 和 Edge 上测试了这个

<style type="text/css" media="screen">
        html {
            -webkit-text-size-adjust: none;
            touch-action: pan-y; /*prevent user scaling*/
        }
</style>

I have used a combination of touch-action and pointer-events to disable all gestures everywhere and allow basic touching only on interactive elements.我使用了touch-actionpointer-events的组合来禁用所有手势,并只允许在交互元素上进行基本触摸。 Works well in Safari in iOS 15. Can be modified to allow some gestures, eg, by replacing none by pan-y etc. I have used it to implement control panels or games that involve quick touching of buttons, which lead to unwanted zoom and scroll gestures.在 iOS 15 中的 Safari 中运行良好。可以修改以允许一些手势,例如,通过用pan-y替换none等。我用它来实现涉及快速触摸按钮的控制面板或游戏,这会导致不必要的缩放和滚动手势。

* {
    touch-action: none;
    pointer-events: none;
}

input, button {
    pointer-events: auto;
}

Also, fixed position efficiently bypasses scrolling and keeps the elements on the screen.此外,修复的 position 有效地绕过滚动并将元素保留在屏幕上。

html, body {
    position: fixed;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM