简体   繁体   English

检测捏缩放iOS

[英]detecting pinch to zoom on iOS

I am trying to detect a pinch to zoom event on iOS (and Android really) because I am using jQuery Mobile to show pages with a fixed header. 我正试图在iOS(和Android上)检测到缩放缩放事件,因为我正在使用jQuery Mobile来显示带有固定标题的页面。 In a dream world what I'd like is for the header not to zoom but for the rest of the page to do so. 在一个梦想的世界里,我想要的是标题不要缩放,而是让页面的其余部分这样做。 But I know this is not possible. 但我知道这是不可能的。

On most pages I have a mobile version that resizes itself nicely making zooming un-necessary, but on the 'front cover' the client wants the user to be able to see the whole page (shrunk to fit) with the fixed header large enough to be usable (ie the same size proportionately as on the mobile optimised pages) and to be able to zoom in on just the cover image- leaving the header bar where it is at the same size. 在大多数页面上,我有一个移动版本可以很好地调整自身大小,使得缩放不必要,但在“封面”上,客户希望用户能够看到整个页面(缩小以适应),固定标头大到足以可以使用(即与移动优化页面成比例的相同尺寸)并且能够仅放大封面图像 - 使标题栏保持相同的大小。

The trouble is that once the user pinches to zoom in, this header bar becomes un-necessarily large. 问题是,一旦用户捏放大,这个标题栏就不一定很大了。

So what I'd like to be able to do is detect the current pinched zoom level and scale down the fixed header bar so it 'looks' the same size (relative to the surrounding phone interface) while the underlying page is zoomed in. 所以我希望能够做的是检测当前收缩的缩放级别并缩小固定的标题栏,使其“看起来”大小相同(相对于周围的电话界面),同时放大基础页面。

I could basically do this with images that fit a 100% width div but I need that div to refit the actual visible area that is left after the zoom, and center itself on drag. 我基本上可以使用适合100%宽度div的图像,但我需要使用div来重新设置缩放后留下的实际可见区域,并将其自身置于拖动中心。

I'd also like to make part of the jQuery Mobile transition, animate the zoom back to 1:1 so the following pages that are 'mobile friendly' are not zoomed in, since they do not need to be. 我还想参与jQuery Mobile转换的一部分,将缩放设置回1:1,以便下面的“移动友好”页面不会放大,因为它们不需要。

So has anyone any ideas where to start here? 那么有任何想法从哪里开始?

You can attach an event to the the body/container of your main page that will report the current scale level. 您可以将事件附加到主页面的主体/容器,该主体/容器将报告当前的比例级别。 For example, using jQuery: 例如,使用jQuery:

  $(container).bind("gesturechange", function(event) {

       var scale = event.originalEvent.scale;

      ...do some logic for header here. 
  });

If you don't use "event.preventDefault", the entire page should scroll correctly, and the header should correct itself as per your logic. 如果您不使用“event.preventDefault”,则整个页面应该正确滚动,并且标题应根据您的逻辑自行更正。 You might also want to bind to the "gesturestart", and the "gestureend" events. 您可能还想绑定到“gesturestart”和“gestureend”事件。

Further reading/explanation: http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html 进一步阅读/解释: http//developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html

" In a dream world what I'd like is for the header not to zoom but for the rest of the page to do so." “在梦境中,我想要的是标题不要缩放,但页面的其余部分要这样做。”

You can set header.style.WebkitTransform = 'scale(' + zoomvalue + '); 你可以设置header.style.WebkitTransform = 'scale(' + zoomvalue + '); within the gesturechange event to "undo" the zoom level (simulate a non-zooming header). gesturechange事件中“撤消”缩放级别(模拟非缩放标题)。

Make your header a fixed width, and apply a zoom in proportion between that width and window.innerWidth. 使标题具有固定宽度,并在该宽度和window.innerWidth之间按比例应用缩放。

AFAIK there is no way to find out the actual zoom level, because it depends upon the device-independent-pixel (DIP) to logical-pixel ratio, and AFAIK there is no way to find out that from JavaScript. AFAIK没有办法找出实际的缩放级别,因为它取决于设备无关像素 (DIP)与逻辑像素的比例,而AFAIK则无法从JavaScript中找到它。

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

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