Animating a circle UIImageView to disappear - objective-c

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.

Related

Blur image in specific area of UIImageView where touch moved

I want to blur the part of image where I move the finger on image view similar to "Touch Blur" application. Many thanks in advance.
Use this library ios-realtimeblur by passing the touch location along with the height and width you want for the same; also add that view as a subview of UIImageView. Make sure every time touch changes remove your previous blur view or change the frame of it.
Hope this helps.

UIButtons titleLabel clips Text after being rotated by CGAffineTransformMakeRotate()

I am developing a iOS-6 app. I have a UIViewController with a view that needs fixed orientation (portrait mode). But when the phone is rotated, one control on that view needs to be moved and rotated (so that it will always be in the upper left corner, and its text will be readable).
I am achieving this by shifting the control(a UIView) using the frame-property of my control (it is a custom view, more on that later), and then using CGAffineTRansformMakeRotate() afterwards, since I know that it's not advisable to use the frame after rotating a view. Everything is fine so far, but here's the thing: That custom view has three UIButtons of type UIButtonTypeCustom as its subviews. Because I rotated the View, but cannot rotate the buttons inside the view (they are not squares), I need to rotate the titleLabels of the Buttons for the text to be readable in the new deviceOrientation.
But it won't work very well. The text will be rotated, as I intended, but it will be clipped by the titleLabel, because the titleLabel has the wrong frame. I checked this by applying borders to the label. So I need to change the titleLabels frame, right? But how can I do that? I tried setting it using [titleLabel setFrame: frameThatFits];, but to no avail. (frameThatFits is a CGRect I created). Also, calling [button.titleLabel sizeToFit]; has no effect that I could see.
I am using [button setTitle:title forControlState: UIControlStateNormal];to set the title.
TL;DR: I'm trying to change the frame/bounds of a UIButtons titleLabel after rotating it using an affine transformation. Any help?
Thanks.
PS: I can supply code when needed, but I wouldn't know what to show you. Tell me what you need, I'll post it.
OK, first of all, thanks to everyone who tried to help. Im posting an alternative solution for my problem, and although it doesnt really address the problem of changing the titleLabels dimensions, it will result in the proper display of my ViewController.
It turns out using the frame is a bad idea. I initially used the frame to reposition the view and i figured that this couldnt be a problem because i only ever applied transformations afterwards, but i was wrong. Because OBVIOUSLY i tried to change the titleLabels frame. AFTER the rotation. And that didnt work.
So the way to go here is using the center-property and the bouds of the view consistently throughout the code. It will result in properly rotated Buttons, that do not need any fidgeting afterwards.
My takeaway here is that i will never ever again use the frame-property outside of a NSLog-statement. But why [button sizeToFit];wouldnt yield any results is still beyond me. If i ever figure it out, i might post it if i remember.
EDIT:
#ZevEisenberg nailed it with this comment:
“Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.” So you are right to use the center and bounds here, but if you do not have a transform, the frame is perfectly safe to use.
NEXT EDIT:
Heres how i ended up repositioning the Buttons:
-(CGPoint)centerForView:(UIView *)view{
//calculate a suitableposition for the view
//depending on the current orientation and the device type (iphone 4S/5, etc)
return point;
}
Then, as a reaction to the deviceOrientation change notification, i apply CGAffineTransformIdentity to all the views, reposition them using my centerForView shown above, and apply the correct rotation transformation to the View. I do this for all the subviews every time the divice rotates, like so:
-(void)setRightRotationTransformations{
[self resetAllTransformations];
self.someSubview.transform = CGAffineTransformRotate(self.someSubview.transform, -M_PI_2);
}
In my case works such hack:
set Line Break mode to Word Wrap
Add extra line to title (even for one line title)

How to make a UIButton auto blink?

Hi i am trying to make a uibutton to blink automatically. i am aware that there is a function "shows touch on highlight" which blink when user touch but i need my button to blink automatically. Is there any way to do it? Thanks!
First of all: Don't do that!!!
But if you do then you could
set timers or use performSelector ...withDelay: or similar stuff to trigger the switching of the images.
Or make the button transparent and layout it on top of a UIImageView. A UIImageView can be set up with an array of images, rather than a single image only, and a time interval used to swap from one image of the array to the next. See the docs for details. It is pretty straigt forward.

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

Animating an MKOverlayView

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.