If anyone came across the google maps app for iOS there is a great feature to zoom in/out with one finger: Doubletap on the uiscrollview and then immediately slide finger up or down to zoom in/out. Does anyone know how this is achieved? Did google post any snippet of that?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- gactions CLI crashes on Windows when uploading goo
- how do you prevent page scroll in textarea on mobi
相关文章
- Windows - Android SDK manager not listing any plat
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
This sample uses regular zooming capabilities of UIScrollView, which contains UIImageView as subview. You can find the implementation of such zooming in MWPhotoBrowser library for example. _imageView, _doubleTapBeganPoint, _longPressBeganPoint, _minScale are your class (UIScrollView subclass) iVars. So begin with initialization:
Standard zoom handler:
Using touchesBegan to catch double tap (UITapGestureRecognizer doesn't want to work with UILongPressGestureRecognizer in some reason):
Handle long press and using difference in Y coordinates to calculate zoom scale. _minScale stores your initial zoomScale so we can restore it.
I added this functionality to my UIScrollView category.
The actual tap recognition is easy, calculating the "correct" (whatever feels "correct")
zoomScale
is the problem… If you think the category isn't handling this good enough, please don't hesitate to tell me and open a new issue on the github page.Use a UIPanGestureRecognizer to track the up/down drag. To ensure it only gets triggered on a double-tap, give it a delegate that does the following:
Now handle the messages coming from the gesture-recogniser. You can derive a zoom scale like so:
This doesn't show actually setting the zoomScale on a scrollview, which is a bunch of extra code - you'll want to get the pan gesture's location and center the zoom around that. You'll also want to clamp the zoomScale, and maybe handle the zoom ending too.