UIScrollView map with pins that stay at a fixed size? - iphone

In my app, I have a ScrollView that shows a map(just a jpeg).
On top of the ScrollView, I added some pins(UIImageView)
So far so good.
But when I zoom in, the pins also get larger.
I would like the pins to stay at a fixed size, just like the pins on the google map application on the iPhone.
How do I solve this?
Thanks!

I've been looking into this for a few days and I've come to the conclusion that there is currently no good way to do this.
First, put your pins as a direct subview of the UIScrollView. Now they'll stay the same size, but will move around when you zoom.
In OS version >=3.2 in UIScrollViewDelegate there is -scrollViewDidZoom:, where you can update the pins to the right coords as it scrolls, and this works great. But in 3.1 we're out of luck. I tried having a NSTimer going and updating the coords instead, but it's not performant on the device.
As a fallback what I do is hide the pins when zooming starts (viewForZoomingInScrollView) and when zooming ends (scrollViewDidEndZooming) update their coords and unhide them.

Make a container UIView that is the same size as the map. Add the map to the UIView with autoresizing of flexible width and height. Add all the pins as individual images, each with flexible margins. Use the container as the zooming view.
If the system autoresizeing does not retain the margin ratio then you can implement layoutSubviews in a custom container view.

Related

How to zoom a selected area of image like pupil meter?

I have to show in zoom of a selected area of image continuously. Means if you are changing position simultaneously zoom also to be change. I don't know how to implement this.
UIScrollView has a great method - zoomToRect:animated: - that allows you to zoom on a specific rect. If you have a UIImageView sitting on a UIScrollView then you can zoom around the image view using this one simple method.

Zoom the page of a view based iOS App

I have a view based application. I have to add features like pinch zoom and double tap to zoom the page(UIView) in the iOS application. Its easy to zoom a UIScrollview.
I should create a framework which has the option to pan and zoom the entire app. How do a achieve to zoom a view based application? I welcome your ideas!
The best way to do it, is to put the entire app components in one scrollview and use the zooming of the control.
The other way which is not as stable as the first one, is to scale all objects inside the UIVIEW larger or smaller depending on the pinch zoom, but keep in mind that scaling will affect the look of the entire application, so you need to adjust the position of each object accordingly.
You can create your own zoom functionalities in a UIView by using UIGestureRecognizer and CALayer transform property. Ex. scaling and change the anchorPoint base on the focus point.

iOS zoom algorithm

I am creating a graphing calculator application in OpenGL on iOS, and I would like to implement pinch zooming that works like the google maps application or uiscrollview zooming. I'm pretty sure I can't use a uiscrollview because the content of the graph is being generated dynamically.
Implementing zooming where the center of the screen is assumed to be the center of the zoom is easy, but in other cases it is not obvious to me how its being implemented. Can anyone point me in the right direction?
The view that does your custom drawing should be capable of drawing at a certain scale. When your user zooms in or out of the scroll view, send the appropriate zoom factor and let the view redraw itself. The changing bounds is not a problem. The scroll view adjusts its bounds as you pan inside, so its subviews shouldn't have any concern over the bounds of the scroll view.
Of course, you'll probably have to consider performance. For example, it may be too slow to redraw the graph at every frame as a user zooms. Instead, you may only want to redraw when the user stops zooming, which is what Maps.app does.
There are many other considerations for this problem, but that would be where I would start.
EDIT: Ah, I overlooked the OpenGL aspect. Still, with a GL layer-backed view, you still should be able to make the appropriate translations based on both the current zoom factor as well as the scroll view's bounds.

Zooming out for the first time in UIScrollView is not smooth

I created UIScrollView and added UIView with lots of tiled UIButtons in the UIView. My problem is, when every time I zoom out the content using zoomToRect method of UIScrollView to the minimum scale I set, the zooming out is not smooth. But zoom-in and zoom-out for the second time is smooth. How can I make the zooming out for the first time to smooth zooming?
Thanks.
The slow initial zoom is obviously due to the phone allocating all the UIButtons the first time it has to draw them. They should be allocated incrementally or before the user starts to interact with them.
What are you doing that requires so much loading and drawing? It doesn't sound like the user would be able to interact with the million or so buttons they might be viewing.
I would suggest adding a pile of code to a UIScrollView Sub Class that makes it aware of it's content size, and it can then init the required UIButtons before the user starts to interact with your UIScrollview, or incrementally as I said.
There is demo code called 'Tiling' that sheds some light on using UIScrollViews to manage large content. It's quite complex, but a very complete demo that I'm sure most projects implement if they handle UIScrollViews with tiled content.
Before zoom out set your UIScrollView* scrollView like:
scrollView.contentInset = UIEdgeInsetsMake(0,0,0,0);

Zooming in UIScrollView is not smooth

I created a minesweeper clone game in iphone. My implementaion of the cells in the grid is this, I created a UIView and added buttons in the UIView and then I added the UIView in a UIScrollView, but every time I zoom out or zoom in using zoomToRect method of UIScrollView the zooming is not smooth and the zoom out was distorted. How can implement smooth zooming in UIScrollView?
I would try rendering your content view into a bitmap image when scrolling or zooming begins, and replacing the large grid of buttons with the bitmap until the scrolling/zooming is completed. The UIScrollViewDelegate protocol should provide you with the necessary information to know when to swap the bitmap in or out. Part of the problem is that your content view is so computationally intensive to render (all those buttons).
A more sophisticated approach would be to re-implement your game grid at a lower level using coreanimation and more fundamental touch event handling, but that might be overkill if the bitmap hack works well enough.
You know how in the maps app, while panning or zooming, there are grey tiles that show up? That means that the iPhone is currently downloading the tiles. In Safari, there is a similar effect where Safari lays down checkered grey instead of webpage, as it is currently rendering it and will be just a moment. Both of these mean that scrolling will not wait for content to load before displaying the area, it will let scrolling be smooth.
You could try looking here [http://stackoverflow.com/questions/1098234/optimized-image-loading-in-a-uiscrollview] for some ideas, and a point in the right direction would be to use threading to load views in the background while displaying grey in its place.