iOS: Adding non zooming buttons to zoomable image - ios

have looked but can't find a solution to this on SO.
The problem: I would like to add buttons to a UIImageView that is zoomable however when the image zooms in, the buttons remain in the same place on the image but do not zoom (ie they stay the same size). This is similar to what Maps does if it has many pins on the map, when you zoom in on the Map if the pins are close together they spread apart and stay the same size, rather than zooming to huge sizes with the map!
My attempt: I understand how to make the image zoom, through use of a scroll view however I am unsure of what the view hierarchy should be. The button locations depend on the image and so you cannot add the buttons to just the scroll as they wouldn't move when zooming. However, if I add the buttons to the image view then they zoom with the image (since I return the image view for the delegate method viewForZoomingInScrollView). I have tried tinkering with an overlayer for the buttons with clues from Zooming a background image without zooming the overlay but haven't found anything that works yet.
Any help is greatly appreciated, thanks a lot!

You should not add the button as a subview to the scroll view. Instead, try adding the button as a subview to your scroll view's superview.
[superview addSubview:scrollView];
[superview addSubview:button];
Your view hierarchy will look like this:
<superview>
<scrollView>
<button>
Since the button is not a subview of the scroll view, it won't get zoomed.

Related

Free Scrolling in Xcode 8.3.3

I want to create a page with a big image as background and buttons that users can interact with.
So imagine I put a big image such as a piece of map into the screen, but I only show a corner of the map in the display. So if a user wants to see other parts of the map, they have to "scroll" and navigate to wherever they want.
Meanwhile I also want to put a button they can tap on, and that button should lead to a php webpage (in-app, not opening in safari or else) or information page about sites and buildings in this location.
I am a rookie and I haven't have any code written down yet. I am thinking about using UIScrollView and UIButton, but am I on the right direction? Any advice?
Thanks in advance!
First you need a way to pinch zoom the image. In this mode, you can drag the image in any direction that you want. A common method can be found here. A scroll view can only scroll horizontally or vertically but with that image zooming, each image can be zoomed in and then dragged to any direction you want. You can have a scroll view with only one image.
After you have the image zooming ready, all you need to do is to create a subview on your screen to cover part of the image view or scroll view, whatever you used.

How to zoom on UIView

In my iOS app I want my users to be able to zoom in on the screen. My main uiview contains several subviews which contain images. I want my uipinchgesturerecognizer to either change the scale, or ideally use some "zoom" rather than scaling each subview.
Please and thank you.
This can be accomplished with UIScrollView. First create a scroll view as the base of your view hierarchy, putting your previous container view as a subview of the scroll view. Set the delegate of the scroll view to self and implement the delegate method viewForZoomingInScrollView, in which you should return the view that will be zoomed in (your original container view). This will allow the user to pinch and zoom your original UIView.
It's hard to provide advice on this without having a clearer view of what exactly you want to achieve.
Can you include a link to a sketch? For example, do you want the individual subviews to remain the same size but the layout to change ? Do you want the individual subviews to resize but their contents to be upscaled?
If you simple want to treat the subview as (basically) a single image which just happens to have other images in it, then maybe it would be better to render it as one and then scale that?

ios - scrollview zooming when scrolling to end, like Fancy

I don't know what this effect is called. Fancy uses it in its app. It works like this.
You have an image at the top of a scrollview.
Drag down and the image gets zoomed to fill the extra top space, so its top edge always remains at the top edge of this scrollview
release your finger and it bounces back
Please give me some idea on how to build this effect. Thanks!
There are many open source implementations of this, such as:
https://github.com/apping/APParallaxHeader
https://github.com/modocache/MDCParallaxView
https://github.com/quemb/QMBParallaxScrollViewController
The basic idea behind these is to have an imageview as a subview of the scrollview. When scrolling, you monitor the content offset of the scrollview, and when you reach a certain threshold, you start increasing the image view's height. If you set the image view's contentMode to UIViewContentModeScaleAspectFill, you will get the effect you want.

ios scrollview - subview out of bounds vertically

I have a dilemma that I cant get my head around to why it act as it does. I have some images that describes the problem. I have a sb:
note! the Image view and the mapview are on top of eachother. Toggling hidden or not depending if I have coords or not to display on map.
I add some dynamic text programmatically under the Sb UIView (and set some constraints. so it looks like this in the end:
Problem now is that if i scroll down a bit so that it looks like this:
Then if I hit the mapbutton to go to nextview that containts a bigger mapview and then return to this view. The scrollview is stuck with parts of the map under the navbar. I can ofc force a scrolldown and see the rest of the mapview but when I release it bounces back and party hides under the navbar once again.
I dont understand shit. And tell me if you want me to try to explain this better its 1.30am and my eyes can barely stay open. But still - any help or pointers are valuable to me.
/Pedro
You can scroll to the top of a UIScrollView using [scrollView setContentOffset:CGPointMake(0,0) animated:NO];.

Scroll view design feasibility - iOS

Im working on a scroll view design where the 'black boxes are supposed to be image items.The blue box is the scroll view. Is it possible to have a zig zag format? And for the count of the box depends on the images available on the internet. So it is more dynamic. Any suggestions would be greatly appreciated!
Yes, you can definitely do this.
You will be positioning UIImageView objects inside the content area of a UIScrollView. Simply set the contentSize of your UIScrollView to reflect the size of your blue box. Think of UIScrollView as a film strip. The UIScrollView is the visible portion of your film, and the entirety of the film is your contentSize.
Now position each UIImageView by setting its frame as you wish and then add it as a subview to the scrollview. If you find yourself needing more horizontal space, you can resize the contentSize accordingly.

Resources