animation in iphone - iphone

I am looking for some reference about the animation such that when you click on the application, it will bring you the first screen but slowly.
Does anybody know what it is please advice me on this issue. Thanks
edit
I just wanna make a nice transition after all.Whenever I click on the application, the first screen just come up. I would like to make it nicer just like the first screen is brought slowly slowly and displayed on the scree. Hope it makes sense now.

I assume you mean fading out the splash screen after the application starts? You can add something like this to applicationDidFinishLaunching to display the splash art full-screen immediately on boot, and then fade it out
UIView *topView = self.window.rootViewController.view;
bootSplashView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
bootSplashView.image = [UIImage imageNamed:#"iPhoneDefault.png"];
[topView addSubview:bootSplashView];
[self performSelector:#selector(fadeBootScreen) withObject:nil afterDelay:0];
And then in a separate method:
- (void)fadeBootScreen
{
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationCurveEaseIn animations:^{
bootSplashView.alpha = 0.0;
} completion:^(BOOL finished) {
[bootSplashView removeFromSuperview];
bootSplashView = nil;
}];
}
Make sure to add 'bootSplashView' as an class variable. If your app can start in different orientation (relevant on the iPad), specialize for those cases by loading a different image.

Well, this is a broad question, but I think you can try Cocos2D for this. There are a lot of examples how to use it, but one simple animation example is this: http://www.raywenderlich.com/1271/how-to-use-animations-and-sprite-sheets-in-cocos2d
Also, there is a good book called "Learning Cocos2D" where there is a good example of managing menus and load layers. http://cocos2dbook.com/
I hope I could help.

UIView has a lot methods for animating them.
Take a look at the View Programming Guide:
http://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6-SW1
The UIView documentation also has a chapter that lists the animation related methods:
http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/UIView/UIView.html#//apple_ref/doc/uid/TP40006816-CH3-SW131
And here's an example for a block based animation, which will fade in a view using it's alpha value:
NSTimeInterval animationDuration = 0.3;
CGFloat startValue = 0.0;
CGFloat endValue = 1.0;
myView.alpha = startValue;
[UIView animateWithDuration:animationDuration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
myView.alpha = endValue
}
completion:^(BOOL finished){
// If you need to do something additional once the animation is finished, place it here.
}];

Related

How to impelment Phone call animation like iPhone's default Phone application does?

My application has VOIP calling. In that I want to implement animation like iPhone's default Phone application does when User Clicks on Call button on dial Pad and animation that is done on End call button.
I have researched alot about this but haven't find anything yet. Any help will be appreciated on this topic.
Right now I have implemented scaling animation like below:
- (void)animateFadingOut{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[self performSelector:#selector(push) withObject:nil afterDelay:0.35];
self.view.transform = CGAffineTransformMakeScale(0.00, 0.00);
//set transformation
[UIView commitAnimations];
}
- (void)push
{
self.view.transform = CGAffineTransformMakeScale(1.00, 1.00);
// push navigation controloller
CallViewController *objCallViewController = [[CallViewController alloc] initWithNibName:#"CallViewController_iPhone" bundle:nil];
[self setHidesBottomBarWhenPushed:YES];
[self.navigationController pushViewController:objCallViewController animated:NO];
[objCallViewController release];
[self setHidesBottomBarWhenPushed:NO];
[[AppDelegate shared] setTabHidden:TRUE];
}
But It is not giving me exact animation that default Phone application has
Here is what I might try if I was trying to create animations.
CGRect movementFrame = self.view.frame;
//Make position and size changes as needed to frame
movementFrame.origin.x = 0;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
/*
Animation you want to commit go here
Apply movementFrame info to the frame
of the item we want to animate
*/
//If you wanted a fade
self.view.alpha = !self.view.alpha //Simply says I want the reverse.
self.view.frame = movementFrame;
//Example of what you could do.
self.view.transform =CGAffineTransformMakeScale(1.00, 1.00);
} completion:^(BOOL finished) {
//Things that could happen once the animation is finished
[self push];
}];
This has not been tested for your case. Therefore I am also not sure if it will help you, but hopefully it will. Good luck to you.
*Edit*
So I reviewed the animation on an iPhone and it appears to me to be a series of animations happening at once.
You have what I presume to be the UIActionSheet animating down.
The top section overlay sliding up its y-axis.
Then you have, which I haven't mastered yet, a split in the back view that animates its x-axis in opposite directions which cause the split.
Finally you have the new view scale up to take frame for the effect.
I can't say 100% this how they have done it, however if I was going to attempt to recreate this, I would likely start here.
Hello there so after just quickly coming up with an animation I got pretty close it could use some tweaks.
It took me three views to do a
topView, bottomView, and backView.
Also took into account the view that you would be loading in. viewToLoadIn
`-(void)animation{
CGRect topMovementFrame = self.topView.frame; //Set dummy frame to modify
CGRect bottomViewFrame = self.bottomview.frame;
topMovementFrame.origin.y = 0 - self.topView.frame.size.height; //modify frame's yAxis so that the frame sits above the screen.
bottomViewFrame.origin.y = self.view.frame.size.height; //modify frame's yAxis to the it will sit at the bottom of the screen.
[self.viewToLoadIn setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
//Animation
self.topView.frame = topMovementFrame; //Commit animations
self.bottomview.frame = bottomViewFrame;
self.backView.alpha = !self.backView.alpha;
self.backView.transform = CGAffineTransformMakeScale(100, 100);
self.viewToLoadIn.transform = CGAffineTransformMakeScale(2.0, 3.0);
*MAGIC*
} completion:^(BOOL finished) {
//Completion
//Clean up your views that you are done with here.
}];
}`
So then When they pressed the button I had setup this animation would happen.
Also at first I thought that the setup might contain a UIActionStyleSheet. which it still might but this is a pretty handy built in functionality. But the fact that you can interact with the screen lead me to think a custom view. It would be easier in my opinion.
I hope this helps you even if it just a little bit.
Take care ^^

How to hide an UI Element slowly

I have a subView that I want to toggle between hidden and not hidden by a button. How do I fade in the subview and fade it out? For now it just appears immediately and disappear immediately when I toggle the button.
I am wondering what is the easiest way to do this animation.
Thanks
On iOS 4.0+ Apple recommends you use their new, block-based animation methods. Using these, the code would look something like this:
[UIView animateWithDuration:2.0
animations:^{myView.alpha = 0.0;}];
The properties you are animating go inside the block (the ^{...} part). Blocks are sort of like functions, so you can put multiple lines of code inside of them, if you want to animate multiple properties. For example:
[UIView animateWithDuration:0.2
animations:^{
view.alpha = 0.0;
view.backgroundColor = [UIColor redColor];
}];
If you need to perform an action after the animation is complete, use the +animateWithDuration:animations:completion: method (which also uses blocks), for example:
[UIView animateWithDuration:0.2
animations:^{view.alpha = 0.0;}
completion:^(BOOL finished){ [view removeFromSuperview]; }];
For more info, check out the UIView Class Reference 'Animations' section and 'Animating Views with Blocks' section.
This is the old pre-4.0 way:
http://objcolumnist.com/2009/07/18/simple-uiview-based-animations-on-the-iphone/
... which has the advantage of being conceptually simple and easy to implement.
float alpha = 1.0; // or 0.0 if it's already visible and you want to fade out
[UIView beginAnimations:#"" context:NULL];
[UIView setAnimationDuration:2.0]; // seconds, not ms. guess how i know?
[mySubView setAlpha:alpha];
[UIView commitAnimations];

Can't interact with UITableView while animations are in progress

I'm trying to implement an animation that happens when a user taps one of my tableview cells. Basically, the animation is just a little label with text like "+5" or "+1" that appears, then moves upwards whilst fading (basically like points appear in video games as the user scores them).
In the tableView:didSelectRowAtIndexPath: implementation of my controller, I'm doing the following (paraphrased for simplicity here):
CGRect toastFrame = /* figure out the frame from the cell frame here */;
UILabel *toast = [[UILabel alloc] initWithFrame:toastFrame];
toast.text = [NSString stringWithFormat:#"+%d", 5];
toast.backgroundColor = [UIColor clearColor];
toast.userInteractionEnabled = NO; // hoped this would work but it doesn't
[tableView addSubview:toast];
[UIView
animateWithDuration:1.0
animations:^
{
toast.alpha = 0.0;
toast.transform = CGAffineTransformMakeTranslation( 0.0, -44.0 );
}
completion:^ (BOOL finished)
{
[toast removeFromSuperview];
}];
[toast release];
The toast is appearing nicely and looks great. The problem is that until the animation completes, the tableview stops receiving touch events. This means that for one second after tapping a cell in the tableview, you can't tap any other cells in the tableview.
Is there a way to stop this from happening and allow the user to keep interacting with the tableview as if the animations weren't happening at all?
Thanks in advance for any help with this.
Another option may be to use animateWithDuration:delay:options:animations:completion: (untested, from the top of my head)
Take a look at the options parameter and the possible flags, defined by UIViewAnimationOptions. Included there is a flag called UIViewAnimationOptionAllowUserInteraction. This could be a solution, maybe you should try it out!
Have you tried doing it the other way? For example, after adding toast as a subview, you can do something like this:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut];
[UIView setAnimationDuration: 1.0];
toast.alpha = 0.0;
toast.frame.origin.y -= 44.0;
[toast performSelector:#selector(removeFromSuperview) withObject: nil afterDelay: 1.0];
[UIView commitAnimations];
and then release toast. You can try it this way and see if it works.

Alternative to CGAffineTransformConcat

In the app I'm working on the user taps on a tableview to zoom it up to full view from a "thumbnail" or a miniature view. Everything is working great except for a somewhat annoying animation glitch or whatever. The thing is I'm using the code below:
if ([subview respondsToSelector:#selector (name)] && [subview.name isEqualToString:self.labelListName.text])
{
[self.tabBarController.view addSubview:subview];
CGRect frame = CGRectMake(35, 78, self.scrollView.frame.size.width, self.scrollView.frame.size.height);
subview.frame = frame;
CGAffineTransform scale = CGAffineTransformMakeScale(1.39, 1.39);
CGAffineTransform move = CGAffineTransformMakeTranslation(0,44);
CGAffineTransform transform = CGAffineTransformConcat(scale, move);
[UIView animateWithDuration:0.15
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{
subview.transform = transform;
}
completion:^(BOOL finished){ [self goToList],subview.hidden = YES; }];
}
- (void)goToList
{
self.gotoWishList = [[WishList alloc] initWithNibName:#"WishList" bundle:nil];
self.gotoWishList.hidesBottomBarWhenPushed=YES;
self.gotoWishList.name = self.labelListName.text;
[self.navigationController pushViewController:self.gotoWishList animated:NO];
self.gotoWishList.scrollLists = self;
[WishList release];
}
And when doing the animation the transfer between the zoom view and the actual view the user is going to interact with is not completely perfect. The text inside the cell jumps a little when switching between the views. The problem lies in the translation matrix. If I skip that I can get the animation to work perfectly but then of course I need to move the miniature view down in the GUI which is not an option. If I instead do the animations in another order (move, scale) then it works better. I still get a jump at the end but it looks better, as everything jumps...and not just the text.
So...basically my question is how can I make this animation fluent. I read that the CGAffineTransformConcat still does each animation separately, and I really need both animations (scaling and moving the list) to be ONE fluent animation.
Thanks for any tips!
I think you will have to nest views/graphic-context to get what you want. The animation system doesn't support simultaneous animations because the mathematics of doing so requires an exponential amount of computational power. You might be able to trick it by sliding one view while enlarging the other.
I'm not sure about that as I have never had need to try it.
You might also be getting a jerk or skip from the tableview itself. The bounce at the top and end of scrolls can produce effects if you radically resize the table on the fly. I would turn all that off and see if you still have the problem. You might also want to test on the view independent of the tableview to make sure the problem is with the animations and not the tableview moving itself.

Simple Animation with NSTimer and opacity for the iPhone

I just want to realize a simple animation, where a picture is faded in a few seconds after the beginning of the application and then it should be faded out and totally disappear. I've never done any animations on the iPhone so I'm stuck. When using something like image.opacity = 1.0; like in the Developer Documentation I get error:
request for member 'opacity' in something not a structure or union.
To fade out an image, you want code like:
[UIView beginAnimations];
myImageView.opacity = 0.0;
[UIView commitAnimations];
You're not setting the opacity of the image itself so much as the opacity of the UIImageView (in this example myImageView) containing the image. You can also control the duration of the animation by adding a line:
[UIView setAnimationDuration: 1.5];
between the calls to -beginAnimations and -commitAnimations.
What you are looking for is the property "alpha", as in view.alpha. You have simply been looking for the wrong name.
Legal alpha values are from 0.0 (fully transparent) to 1.0 (fully opaque). It will do exactly what you are looking for.
Use the beginAnimations/commitAnimations paradigm referenced in the comment above.
Summarizing the other answers:
To fade out an image, you want code like:
// This line may not be necessary.
myImageView.alpha = 1.0f;
[UIView beginAnimations];
[UIView setAnimationDuration: 1.5];
myImageView.alpha = 0.0;
[UIView commitAnimations];
the solution above didn't work in my project. I had to do it like this....
**[UIView beginAnimations:#"myPic.png" context:nil];**
//You need to set the pic name
[UIView setAnimationDuration: myTimer];
_myPic.alpha = 1.0f;
_myPic.alpha = 0.0;
[UIView commitAnimations];
this is to fade out an image
regards
Philipp
It seems you want a fade in and then a fade out. But time to kick in after a duration. Not just the duration of the animations themselves.
I do not normall do stuff for iOS, so forgive me if I have the code in the wrong place.
This was tested on the simulator and in a single view application.
I added a new UIview to the ViewController's UIView and linked it to its .h file as an outlet. (named it theView)
Then added a UImageView to the new UIView (theView ) and set an image for the UImageView using the attributes inspector.
Then added code to the ViewController.m file.
The main thing I want to show you is the
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
Which invokes a method of the receiver on the current thread using the default mode after a delay.
(There are similar methods that can perform on other threads…)
I have made two methods one that fades in and one that fades out.
There are two performSelectors.
The first is called when the view loads.
The second is in the fadeIn animation block. You can place this in the viewDidLoad or after the block. But I thought it would be safer to have it where it is.
here is the .m file code.
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_theView.alpha = 0.0;
[self performSelector:#selector(fadeIn) withObject:nil afterDelay:2.0];
}
- (void)fadeToBlack
{
[UIView animateWithDuration:3.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{_theView.alpha = 0.0;}
completion:nil];
}
- (void)fadeIn
{
[UIView animateWithDuration:3.0
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{_theView.alpha = 1.0; [self performSelector:#selector(fadeToBlack) withObject:nil afterDelay:10.0];}
completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I am expecting corrections here… as this is not really an area I am fully familiar with (ViewControllers) But its works ok in the sim.