I have a map view with an overlay. I want to restrict the user from zooming out too far. So if the user scrolls out and cant see part of the overlay it zooms them back in to the max height of the overlay. Like the zooming I also want the user not to be able to scroll of the edge.
I have managed to implement this (or so I thought). The code that I have written works on my iPhone 5 but then when I tested it on my Bosses phone and the simulator the map keeps trying to resize and get stuck in an infinite loop.
Here is a video of my app in the Loop.
From the video I can see that the map should loop as both edges are displayed off the map. To stop this my code zooms in so you cant see both edges before it is meant to move back to the edge the user has moved from.
As I said this works on one of my device but not the others! I have been trying to fix this for three days now and feel like banging my head on the keyboard! Any help would be amazing.
Here is a copy of my Code.
I have commented it and tried to make it easy to under stand.
EDIT: just updated to iOS 6.0.1. It still works on my iPhone 5 but It starts really far zoomed in and sets the min zoom too low
I have extracted some code from the PhotoScroller sample code from Apple to use the CATiledLayer. I have an image of 8000x7000px loaded from internet, in tiles.
This is kind of a map-function in my app. I also have two almost identical images, with different overlays (tried to only add the overlay without luck).
I have an UISegmentedControl to toggle between the three choices, and I want the imageView to load the images from the selected image. So if the user zoomes in on one of the images, and selects another option, then the scale and coordinated stays the same, and the imageView loads the chosen image in the necessary tile-spots.
I have partially managed this. Or, I have actually managed this, but when I select another option, the whole screen goes black when the function [imageView removeFromSuperview]; is called. After being black in a couple of seconds(depending on internet speed) it shows the correct tiles.
I want the layer to "fade" over to the next layer if possible. As you maybe know, when using CATiledLayer, the first layer is the whole image in low resolution, but when zooming in, the necessary tiles "fade" in to the next layer with smaller tiles.
I basically need to give the (TilingView*)imageView a "reload"-command, and want it to "fade" over the last image.
I tried to comment out the [imageView removeFromSuperview];, and that actually got me close to what I want. When I zoomed in, and selected another option, the new image actually faded over the old one, however, when I zoomed back out, the old image was clearly sticking around in the background(behind the new image), not responding to anything. I need to remove it from the superView at a later point, but I have no longer access to it as the new image has taken its place as imageView. I know people might want to see code here, but I have really no idea what code to show.. And the CATiledLayer is SO POORLY documented I am really having a hard time understanding what's going on.
I made it work through some sketchy code. There probably are other better solutions, but this is the only one I know of at the moment.
The problem was that when I removed [imageView removeFromSuperview];, it did not unload the last image, thus letting it be in the memory forever. As it was not affected by zooming and scrolling, when I zoomed out, it was always there in the background. If I was to switch between options multiple times, multiple images would add up in the background.
I simply created a "helper" as I call it. A new imageView, which gets the content of the old imageView when switching option, without removing it from the superview just yet, as a premature removal results in black screen when the new image hasn't loaded quite yet.
I now call the [helper removeFromSuperview]; in the delegate methods scrollViewWillBeginZooming AND in scrollViewWillBeginDragging. This results in memory containing at the most two images in the time between clicking the other option, and user scrolls or zoomes.
Note: If the user scrolls or zoomes immediately after switching option in the UISegmentedControl, it turns black because the new image hasn't been loaded yet.
I have a big UIimage (2000x2000). Image drawed every time on app start, and copied to CALayer.
On Current time i put UIScrollView on main view, and make CALayer with drawn image.
Scrolling on small zoom looks fine. But on min zooming , when whole image visible, image scroll slowed, it becomes not quick responsible on move touch.
So, the question. What can I do, to increase scrolling performance?
The approach I would take is to use a lower resolution version of your image at lower zoom levels (lower = zoomed out).
First, see this post for resizing UIImages.
Respond to the scrollViewDidEndZooming:withView:atScale: method in UIScrollViewDelegate, and switch the images when a certain zoom level is reached. This will take some trial and error to find the correct balance. You may even want to render your image at several different resolutions. Be sure to generate the different sized UIImages in advance so there is no delay while zooming.
I have a graphic that is 3 times the width of an iphone landscape view.
I am trying to auto scroll it so that it appears that it is moving sideways, without using the touchscreen scrolling method.
My aim is to maybe have a button you can press and it moves it left or right across the screen like an animation.
I can deal with everything else but am having trouble finding a solution.
Any example code would be appreciated or even any info on whether it is possible or not.
Thanks. Dave
You can wrap a UIView in an animation block. The animation sweeps the origin value in its frame property from one point to another, over a set period of time.
By overriding the drawrect of my MkAnnotationViews, I am displaying paths using CoreGraphics. The problem I have is when I zoom in pretty close and scroll the map view, the paths drawn by CoreGraphics seem to be really jumpy, as if they are updated only after a shift of three or more pixels. When zoomed out, the scrolling is perfectly smooth and is reflected for each pixel shift. The drawrect function is not called during this scrolling as I assume mkmapkit is just applying translations on the existing views. Any ideas how to smooth this out or why this is happening?
Here is a youtube video that I posted showing the issue using the iphone simulator. Of course, I have the same problem on the actual device as well.
http://www.youtube.com/watch?v=AvWx5Yz4oxI