How to fade the colour of a button to another colour? - objective-c

I am trying to change a button from one colour (red) to another colour (yellow) when another button is pressed. I currently have an abrupt change from red to yellow, and would like to add in a quick animation to make the transition a bit smoother. How would I go about doing this? Any help would be much appreciated.

UI updates should happen in main tread, but the animation method is in UIView, it is meant to this:
[UIView animateWithDuration:desiredDuration animations:^{
object.property = newValue;
}];

Related

How to pinch view on button press?

I've got the button on the fullscreen UIImageView and I want to pinch this view on that button press. I mean, I want to show only the part of the UIImage to the fullscreen after the button is pressed. Which method should I use?
Basically you can just start a zoom Animation, if that is all what you want.
Example:
[UIView animateWithDuration:1.0 animations:^{
yourView.transform = CGAffineTransformMakeScale(2.0,2.0);
}];
Put your UIImageView inside a UIScrollView to get zooming and panning.
See this SO post. I've already used this technique and it's the only way I know to do it.
you will want to use the pinchGestureRecognizer :)
http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIPinchGestureRecognizer_Class/Reference/Reference.html

Flip UIView (reversi style)

I'm trying to make a reversi game, and want to flip a piece to the opposite color. So when a white piece is flipped, it becomes black, and the other way around.
I know you can flip a UIView with the code below, but can't figure out how to flip it to another image.
In my "Piece" class, I have a UIButton with the black or white image. Do I need to create two buttons, and then flip them somehow?
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:card cache:YES];
Thanks in advance
I would do this to do a transition from the white button to the black button in 0.4s.
You need to have your white and black buttons already as subviews of some other view. For this transition the black button should be hidden before doing the transition.
UIViewAnimationOptionShowHideTransitionViews says that your fromView will be hidden after the transition.
The flip will occur in the whiteButton superview.
[UIView transitionFromView:whiteButton
toView:blackButton
duration:0.4f
options:UIViewAnimationOptionTransitionFlipFromRight |
UIViewAnimationOptionShowHideTransitionViews
completion:^(BOOL finished){}];

How can I implement a pointer arrow on a toolbar in iOS?

I'm looking to implement a pointer arrow above the currently selected toolbar icon much like the design found in Reeder and Instacast:
The pointer arrow should move across smoothly when another toolbar item is pressed. I need to be able to choose which items cause the arrow to move, as featured in Instacast and Reeder, where only certain items change the arrow position.
Can I do this without too much overhead and a lot of UIKit subclassing?
This shouldn't be too bad: just take an image of the little triangle like you have in your question, and put it in a UIImageView that sits above the toolbar.
Then set it up so that when the action: for the relevant toolbar button is called, the UIImageView slides so that it's in the right place, with animation. Something like:
[UIView beginAnimations:#"TriangleAnimation" context:NULL];
[UIView setAnimationDuration:0.25];
triangleImageView.frame = //new location here
[UIView commitAnimations];

How can I start animating an UILabel from a particular location in iPad?

I need to start animating a UILabel when a button is pressed... the animation should start from the position of the button.
How can I achieve this?
i.e moving label from one end of the screen to another end.
This is acheviced with UIView's animateWithDuration methods, which can be found in the documentation here.
A very simple example which should be called when your button is pressed:
[UIView animateWithDuration:0.5 animations:^{
// set new position of label which it will animate to
myLabel.frame = CGRectMake(x,y,width,height);
}];

Animate the change of a stroke color on UIView

I'd like to "pulse" the stroke color on a path that I've drawn in a UIView's drawRect. But not sure this is possible?
- (void)highlightView {
if (!isHighlighted) {
[UIView beginAnimations:NULL context:nil];
[UIView setAnimationDuration:0.75];
self.strokeColor = kHighlightColor;
self.strokeWidth = 2.0;
[UIView commitAnimations];
self.isHighlighted = YES;
}
}
I'm only able to see the change if i setNeedsDisplay on the view. But that bypasses the animation. I can think of a few workarounds if this isn't possible like overlaying another semi-transparent view with the proper color and just fading it in... but for some reason I thought animating color properties was possible in Cocoa?!? Perhaps I'm mistaken. Hopefully one of you can set me straight.
You absolutely can animate colour properties with UIView, but it doesn't really make sense in the context you're dealing with right now.
In drawRect: you are essentially painting a colour when you stroke a path, those bits just get blitted to the screen. At that point, the colour isn't really a property of the view so much as part of the painting.
I wrote a UIView that pulsed this summer (emulating the "In Call" status bar) by creating two UIViews stack atop each other, and animating both of their color properties.