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.
Related
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.
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.
I'm writing a card game and need a animation to flip them over from one side to the other along the y axses. What would be the easiest way to do this? Is there any good tutors?
This is what I did:
Found some sample code for using UITransitionView. But it comes up as undeclared on my sdk, and I found out this was undocumented.
Looked into OpenGL, seems to complicated.
Any help would be GREAT!
Ted
Here is some code that I used in a blackjack app tutorial I went through:
-(void) flipCard {
[UIView beginAnimations:#"Flip Top Card" context:nil];
[UIView setAnimationDidStopSelector:#selector(flipCardDone)];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationRepeatCount:0];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:topCard cache:YES];
topCard.image = [UIImage imageNamed:#"back.png"]; //begin
topCard.image = [UIImage imageNamed:currentName]; //end
[UIView commitAnimations];
}
-(void) flipCardDone {
topCard.hidden = YES;
nextCardToFlip.hidden = NO; // bad var name, nextCardToFlip ONLY appears to flip.
}
I hope it helps you :)
The simplest way to do this would be to use UIView transitions, or CATransitions depending on what exactly you're trying to accomplish.
Documentation for the UIView animation can be found here.
This is an absolute beginner's question (sorry), but I was wondering how to commit one animations and once it has ended to start another one. Imagine having an image moved from x=0 to x=300. Then you want to do animate the same image again, but this time from x=300 to x=330 so that it disappears from the screen.
The following code will only do the animation from x=300 to x=330 and will not commit the animation x=0 to x=300. I'm sure I don't get the concept of commitAnnimation and that this is obvious, but how would I do two animations after one another?
I know I could move the image straightaway to 330, but I don't want this as I need the first animation (x 0 - 300) to be in sync with another animation.
Here is my (wrong) code:
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 300, 0)];
[UIView commitAnimations]; // End animations
// Second Animation
[UIView beginAnimations:#"shadowMoveRestAway" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 330, 0)]; // Move imageView off screen
[UIView commitAnimations]; // End animations
Use the delegate method
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
to start something else when the first animation has finished. So put what you want to do next inside the animationDidStop:finished:context method, remember that the iphone is an event driven environment so linear code like you have above will simply kick off each animation at almost the same time.
EDIT:
I forgot to add that you need to set the animation delegate as well otherwise you won't get the event when the first one stops - see below;
Here's a full version of your code with the change - I'm using the abbreviated animationDidStop delegate as that's easier to understand and fine for this example.
[UIView beginAnimations:#"shadowMove" context:nil]; // Begin animation
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myFirstAnimationDidStop)];
[imageView setFrame:CGRectOffset([imageView frame], 300, 0)];
[UIView commitAnimations]; // End animations
Then you just need a new method like this;
-(void) myFirstAnimationDidStop {
// Second Animation
[UIView beginAnimations:#"shadowMoveRestAway" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[imageView setFrame:CGRectOffset([imageView frame], 330, 0)];
[UIView commitAnimations];
}
And for completeness, in your interface (.h) file you should add;
-(void) myFirstAnimationDidStop;
#selector is easy, it's just a way of pointing to another method - hopefully this example clarifies that.
I have a UIScrollView and I'm calling scrollRectToVisible:animated:YES on it.
I would like to set the speed at which it is animated. Can that be done?
I ended up finding a solution. In my case, the scrolling was animated programmatically after launch, to mimic a slot machine (with 3 horizontal UIScrollViews). Was doing this with the scrollRectToVisible:animated: method.
I got to set a custom speed using UIView's beginAnimation:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:(abs(rMid-pMid)*0.3)];
scrollMid.contentOffset = CGPointMake(rMid*320, 0);
[UIView commitAnimations];
AnimationDuration depends on the distance the scroller has to move between each "drawing".
A modern version with blocks:
[UIView animateWithDuration:1.0 animations:^{
[self.scrollView scrollRectToVisible:CGRectMake(...) animated:NO];
} completion:^(BOOL finished) {
...
}];