How to implement UIViewAnimationOptionBeginFromCurrentState - iphone

I have a piece of audio & associated Play & Stop buttons, when the Play button is pressed I use an animation of a curser to denote at which point in the audio sample we are, at a given moment. Whenever the stop button is pressed I want my curser to return to its initial coordinates. I believe UIViewAnimationOptionBeginFromCurrentState might be the way to do this? My code for the initial animation is below, anyone have any tips on how to use UIViewAnimationOptionBeginFromCurrentState in order to send the cursor back to its original coordinates?
Thanks for any help in advance :)
[UIView beginAnimations:#"MoveView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:2.0f];
yellowBar.frame = CGRectMake(310, 20, 5, 100);
[UIView commitAnimations];

If you are still using beginAnimations/commitAnimations, use setAnimationBeginsFromCurrentState:. Otherwise, you can pass UIViewAnimationOptionBeginFromCurrentState to animateWithDuration:delay:options:animations:completion: for the options parameter.

Brian is right, you have got two alternatives:
//Initialize newFrame here
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState //Multiple options
animations:^ {
[yourView setFrame: newFrame];
}
completion:^ (BOOL finished) {
}];
Or
//Initialize newFrame here
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[yourView setFrame: newFrame];
[UIView commitAnimations];

AFAIK you can only use that option with block-based animations (which you are encouraged to use anyway). You'd use the animateWithDuration:delay:options:animations:completion: method, described here.

Related

how to hook UIView's animation?

I want to send my own message during UIView's animation process.
For example:
myView.alpha = 1.0;
[UIView animateWithDuration:2.0f animations:^{myView.alpha = 0.0;} completion:^(BOOL isFinished){}];
I want to send the message when iOS render the specific alpha's animation frame.
- (void) alphaChangedTo:(float) val
{
[sendMyOwnMessage:val];
}
as the animation is carried out by the iOS system, can I hook the function to finish my task?
Thanks!
Have you tried animation code block??
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[sendMyOwnMessage:val];
[UIView commitAnimations];
I am not sure if this is what you are looking for.. but I hope this helps.. Cheers!! Happy Coding.

How to customize UIAlert View..?

I have customized the UIViews by adding images to make it look like radio button or check boxes, but for my spec I want to make the UIAlertView look like this...
Can anyone suggest how to do this?
Thanks!
You can design custom view and can give animation to it as alert view using this code
-(void)initialDelayEnded
{
alert_upload.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
alert_upload.alpha = 1.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1/1.5];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounce1AnimationStopped)];
alert_upload.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
[UIView commitAnimations];
}
- (void)bounce1AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5/2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(bounce2AnimationStopped)];
alert_upload.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
[UIView commitAnimations];
}
- (void)bounce2AnimationStopped {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5/2];
alert_upload.transform = CGAffineTransformIdentity;
[UIView commitAnimations];
}
alert_upload is UIView.
There’s many previous questions about this topic, one of them links this component that lets you create custom alerts and action sheets. Might be a good way to start.
You can create your own customized alert views, Apple wont reject it until unless user interaction.

different type of animation in iPhone

I am new to iPhone developer,
I want to implement different Animations on button click, i have 5 Button in my home page
on each click of button, i want to navigate to a new page with different Animation so i want to know what are the different animation available in iPhone.
so far i have found only 2 animation,
(1)
[UIView beginAnimations:#"yourAnim" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:yourView cache:cacheFlag];
...
[UIView commitAnimations];
(2)
[UIView beginAnimations:#"yourAnim" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:yourView cache:cacheFlag];
...
[UIView commitAnimations];
Thanks In Advance !
This link provides the UIView Animation. Go through it.
http://www.raywenderlich.com/5478/uiview-animation-tutorial-practical-recipes
These are 5 different Animation Transition:
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
Look at CATransition class too
https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CATransition_class/Introduction/Introduction.html
I think bellow method from you can test different type of Transition Animation....
- (void) pushController: (UIViewController*) controller
withTransition: (UIViewAnimationTransition) transition
{
[UIView beginAnimations:nil context:NULL];
[self pushViewController:controller animated:NO];
[UIView setAnimationDuration:.5];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:transition forView:self.view cache:YES];
[UIView commitAnimations];
}
You Can Get Idea From this May Be.....

two UIView Animation on the same image

Well I would like to have two UIView animation on a same image in the same method like this :
-(void)likeThis{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
image.alpha=0;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
image.transform = CGAffineTransformScale(5,5);
[UIView commitAnimations];
}
But there is only one of these UIView Animation who work.I don't know why.I think there is another way to put two animation for the same image but I don't know how. sorry for my english I'm french :/
You can just put them in the same animation block:
-(void)likeThis
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
image.alpha=0;
image.transform = CGAffineTransformScale(image.transform,5,5);
[UIView commitAnimations];
}
Note that CGAffineTransformScale takes three arguments:
CGAffineTransformScale(image.transform, 5.0, 5.0)
See http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/doc/uid/TP30000946-CH1g-F16985
Or you could use CGAffineTransformMakeScale:
http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/c/func/CGAffineTransformMakeScale
Do you want them to happen simultaneously, or one after the other? If the former just include them both between a single set of beginAnimations..commitAnimations calls

Trouble with UIView Animations - performing the same animation more than once doesn't work

I need to flip a card and then flip it back. I have written code to do that with no trouble. The trouble comes because users can flip this card back and forth as many times as they want, and it seems that the effect is cumulative. On the second try, the card spins like a top. I'm not completely surprised, as there only seems to be a way to add animation, not clear one from the view. Is there a way to 're-set' a UIView of any animations I had previously committed? Is there a way to capture it and re-use it without committing a new one? Or am I missing something obvious? This is my code:
if (self.flipped) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self
cache:YES];
[imageView removeFromSuperview];
[UIView commitAnimations];
self.flipped = NO;
} else {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self
cache:YES];
[self addSubview:imageView];
[UIView commitAnimations];
self.flipped = YES;
}
Thanks for reading.
To cancel all ongoing animations:
#import <QuartzCore/QuartzCore.h>
...
[view.layer removeAllAnimations];
To start a new animation that kills existing animations, if any, and starts the movement from wherever the view currently is — which I think is what you want:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
... and the rest of it ...
[UIView commitAnimations];
Hopefully one of those will solve your problem.
Whatever your "self" is, put it in a containing view called foo, and then change your setAnimation... line to this:
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:foo
cache:YES];