Animating an MKOverlayView - objective-c

I have an MKOverlayView that displays animated radar data as a series of images. The issue I have is that the radar images are chopped into tiles by MapKit. To swap images I have a timer that calls an update function which sets the current image in my overlay and then calls the following
[myRadarOverlayView setNeedsDisplayInMapRect:self.mapView.visibleMapRect];
The overlay updates, but does so one tile at a time so I get a choppy animation. Any ideas about how make all the tiles animate (i.e. swap images) at the exact same time?

I solved this by adding a UIImageView as a subview of the MKOverlayView.
To animate, stop drawing with the
normal
drawMapRect:zoomScale:inContext: (via
an instance variable/property flag) and
draw to the UIImageView instead (to
the animationImages property), then
use startAnimating.
You can handle panning and zooming by
reinitializing the UIImageView in
response to
mapView:regionDidChangeAnimated:.

Sample code how to animate a circle:
http://yickhong-ios.blogspot.com/2012/04/animated-circle-on-mkmapview.html

Is there a callback when all the tiles have finished loading? If so, you could go with double buffering, and update the view offscreen, and then switch it in.

Related

Animating a circle UIImageView to disappear

If I have a UIImageView of a circle, how could Core Animation make it disappear like in this question?
How to use CoreAnimation to animate a circle like a clock countdown
Create a CAShapeLayer. Set its path to your “clock” shape. Set it as the layer mask of your image view (e.g. imageView.layer.mask = shapeLayer).
Then you can try using a CAKeyframeAnimation to animate the shape layer's path, but I suspect the results won't be pleasing. Instead you'll probably want to use a CADisplayLink as a timer and update the shape layer's path every time it fires.
What you are looking for is known as a "clock wipe" transition.
David is pointing you in the right direction. I have a sample project on Github that shows exactly what you are looking for:
iOS Core Animation Demo
When you run the app, click on the "Mask Animation" button. It does what you're talking about. It shows an image view with a clock wipe, and then hides it again. It would be a simple matter to switch it around to have the image fully visible at first and then animate a clock wipe to hide it.

Can a UIViewImage draw its image outside its frame?

When making a photo viewer app found that our UIImageView controller is drawing its image outside its frame when the content mode is different neither ScaleToFill nor Aspect Fit.
Trying to understand why; I isolated the problem making a new project which only has a UIImageView with the following frame (50,50,100,100). The image size contained in it is (4592,3056).
After running the app, with the content mode set to ScaleToFill and AspectFit it all worked as expected:
But after setting the contentMode of the UIImageView to TopLeft, the image is drawn outside its frame, the odd thing is that the log from the frame after all has been drawn is still the original {50,50,100,100}.
I've try to understand the issue by moving the Autoresize, the clips and the content mode of the UIViewController but the result is the same.
set clipToBounds = YES on the view.
its NO by default because that makes drawing way cheaper

animate pan gesture

i have wrote a subclass of UIView, which in drawRect: draws itself. it is actually something like day-long timeline for movie - it draws time axis with ticks and time text labels. it can be zoomed in up to seconds and zoomed out up to all 24 hours. when its zoomed in, it could be scrolled with pan gesture. so here is the question: how can i implement simple animation, when the finger is lifted, timeline continues to scroll for a while and then stops (with negative acceleration)?
two ideas comes to my mind:
implement animation by myself using another thread
make new class - a subclass of CALayer and then use CABasicAnimation. add this class to the layers of my view. but here i should totally move all my code written for view to new subclass of CALayer, what i dont want to do. would it be ok?
any other ideas?
Wouldn't it be easier to integrate the view in a UIScrollView, let that handle the scrolling and zooming and let your class just do the drawing?

How to keep an object in view of a scrollview while animation moves the object offscreen

Good day all;
I have an UIImageView that I animate around a large UIView. The UIView is contained within a UIScrollView.
Now, with small movement animations of the UIImageView within the UIView, if it passes a certain thresh hold (gets close to the edge of the screen), I will manually scroll the UIScrollView to re-center the UIImageView. The code is synchronous in that I animate the UIImageView and then scroll to point in the UIScrollView.
Where I am having an issue is when there is a really long movement animation, the entire scrolling process struggles and I get a lot of skipped frames. I am not certain bit I think it is due to my synchronous code and I believe I need a way to execute the scrolling and the animation at the same time but I have no idea how to do it.
Is there a way to make the scrollview listen to where the UIImageView is at all times and center it when it passes a thresh hold even when in the middle of executing an animation?
By the way, I have disabled the user from scrolling the UIScrollView.
Thanks in advance.
Sorry I have left this for so long, I actually solved this a long time ago but forgot to post my solution.
Basically, pass the UIScrollview to the animated object (a layer or view). The animated object will have itself as a delegate for the animation and implement the methond "animationDidStart:(CAAnimation *)theAnimation".
If you persist the destination location in the animated object and the UIScrollView, then you can compute where to move the scrollview in the "animationDidStart" method.
Beware that the content offset and you destination location in the scrollview must be scaled if your scollview has been scaled. (Trap for young players)

Animate the drawing of a line (Quartz 2D?)

How would you go about animating the drawing of a line in a UIView on the iPhone? Is this possible? It can be drawn but can it easily be animated so it appears to be hand drawn?
There's no built-in way to do this no. You'd have to redraw the line repeatedly, interpolating between the start and end points using a timer callback to invalidate the view and trigger a redraw. Of course the redraw would have to draw everything in the area of the view bring redrawn which is potentially slow.
What I would do if I had a series of lines I wanted to draw over a period of time is to have two subviews - they would cover the same area and the top one would have a transparent background. Have the top one draw just the line that I am currently animating and when it's finished, draw the full length of it in the lower view. Then repeat, animating the next line in the top view.
With the new API you can do that easily, using strokeEnd property of CGPath.
You can read more details here: What's the easiest way to animate a line?