Customized Animation in iphone - iphone

I am creating Application which have so many Customization. Customization in the sense, I want to give new look to my application. In the part of customization I want to add THIS kind of animation inside my application.
i have searched over internet finally i found so many 3d animations. But those results are not satisfy my needs.
Suggest me some piece of code to make that animation possible.
If u provide any source code, That will be really helpful for me.

This is exactly you want.Set your view like this.
_transitionFrame is label outlet.That label is placed on your display view.
Include QuartzCore framework and define a method to convert degree to radians like this
#import <QuartzCore/QuartzCore.h>
#define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
In view did load Method write following code.
- (void)viewDidLoad
{
CGRect preFrame=_transitionFrame.frame;
preFrame.origin.y+=preFrame.size.height/2;
[_transitionFrame setFrame:preFrame];
[UIView beginAnimations:nil context:nil];
CATransform3D _3Dt = CATransform3DRotate(_transitionFrame.layer.transform,DEGREES_TO_RADIANS(90), 1.0, 0.0,0.0);
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:100];
[UIView setAnimationDuration:1];
[_transitionFrame.layer setAnchorPoint:CGPointMake(0.5, 1)];
_transitionFrame.layer.transform=_3Dt;
[UIView commitAnimations];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

Related

Rotating button when downloading data from server

I want to rotate a UIButton when connection start and want to stop rotating when connection stop.
So my question is how to start or stop rotation on UIButton.
I use the following code for rotation.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:5.0];
// (180 * M_PI) / 180 == M_PI, so just use M_PI
btn.transform = CGAffineTransformMakeRotation(M_PI);
[UIView commitAnimations];
You can remove animations from a view by calling removeAllAnimations
[btn.layer removeAllAnimations];
Make sure you import QuartzCore before accessing layer properties, otherwise you may get a warning.
#import <QuartzCore/QuartzCore.h>
To make the view animate continuously use the + (void)setAnimationRepeatCount:(float)repeatCount method on UIView and set it to some arbitrary high number.
[UIView setAnimationRepeatCount:5000];

UITabBarController View Transition error

OKay I have been working on this problem for a while now, And It is well beyond my expertise thus why I am asking for help again.
I am trying to animate the transition for a tabbarbutton click to another view. I have declared in both viewController (ViewWillAppear) methods the code below
- (void)viewWillAppear:(BOOL)animated
{
//TODO: Fix transition animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];
[super viewWillAppear:animated];
}
FirstViewController to the right and SecondViewController to the left.
Now the problem is happening when the user loads the app for the first time, once everything loads up and the user clicks on the tabbarbutton to go to the second view, it dose not flip.. but when you go back to the FirstView it animates then if you go to the second again it will animate this time round.. Dose anyone have any idea why this is happeneing? if you do your help would be greatly appreciated!
UPDATE::
I am trying to add a animation into viewDidLoad, however there is already an animation for an opening sequence I am loading straight away.
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//-- Start Opening Animation ------->
CGRect vaultTopFrame = vaultTop.frame;
vaultTopFrame.origin.y = -vaultTopFrame.size.height;
CGRect vaultBottomFrame = vaultBottom.frame;
vaultBottomFrame.origin.y = self.view.bounds.size.height;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.5];
[UIView setAnimationDelay:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
vaultTop.frame = vaultTopFrame;
vaultBottom.frame = vaultBottomFrame;
[self.view bringSubviewToFront:vaultTop]; //this should place this subview above any others on the same page
[self.view bringSubviewToFront:vaultBottom]; //this should place this subview above any others on the same page
[UIView commitAnimations];
I think this might be messing things up for me what do you think?
You do not have animation when the app loads up. Set animation in viewDidLoad for animation when the view loads up and viewDidAppear will give you animations when the user makes transition after wards (every time the tab is clicked).
This may or may not be the problem, but you should call
[super viewWillAppear:animated];
at the beginning of the method, before your animation code.

How to properly release a view after a UIView Animation ? :)

I have a method like the following:
- (void)add:(id)sender {
MyAddViewController *controller = nil;
controller = [[MyAddViewController alloc] initWithAddType:1];
//controller.delegate = self;
// Do some animation. Slide it in from the right side of the screen.
CGPoint initialCenter = self.view.center;
controller.view.center =
CGPointMake(initialCenter.x + 320, initialCenter.y);
// Add the subview now with it's center + 320 off the screen.
[self.view addSubview:controller.view];
[UIView beginAnimations:#"animation" context:NULL];
[UIView setAnimationDuration:0.35];
[UIView setAnimationDelegate:self];
controller.view.center = CGPointMake(initialCenter.x, initialCenter.y);
//[UIView setAnimationDidStopSelector:#selector(aMethodToBeCalledAfterAnimationEnd:finished:context:)];
[UIView commitAnimations];
//[controller release];
}
You see I have a controller release as the last line in my add method. If I uncomment this line the animation completely dies and it just dumps the view into place with no animation.
Is there a better way to do release without having to create another method which does cleanup via [UIView setAnimationDidStopSelect:#selector(aMethodToBeCalledAfterAnmiationEnd... ?
Or can I do something like setAnimationDidStopSelector:#selector([controller release]) ? :)
Thanks in advance!
Using setAnimationDidStopSelector: is the proper way to solve the generic problem of releasing resources after an animation completes.
Take a step back and reconsider what you're doing here, though. Why are you looking to free the controller you just created? If you are only creating the controller for the purpose of getting at the view, that isn't the right way to do it. Build yourself a factory method to create your view, or use the methods in NSBundle to load the view from a NIB.
You can do this:
[UIView setAnimationDelegate: controller];
[UIView setAnimationDidStopSelector:#selector(release)];
I see you tagged this iphone-sdk-4.0. You could use the new block-based animations to do this and any other cleanup. See the documentation for details.

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.

Scale/Rotate a button in interface

I need to rotate a button by 30 degrees in iphones sdk interface builder, how do you do that?
You can't do it in Interface Builder, but the code is pretty straightforward.
Make sure you've connected the button in IB to an IBOutlet of type UIButton* (let's call it myButton). Then once the nib has been loaded (for example, in your viewDidLoad method) you can use something like this:
#define RADIANS(degrees) ((degrees * M_PI) / 180.0)
CGAffineTransform rotateTransform = CGAffineTransformRotate(CGAffineTransformIdentity,
RADIANS(30.0));
myButton.transform = rotateTransform;
I'm not sure that you can do it directly. You might be able to do it if you were drawing your own buttons via CoreGraphics layers.
Core Animation Layers
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
button.transform=CGAffineTransformMakeRotation((0.0174532925)*30);
//put the -ve sign before 30 if you want to rotate the button in the anticlockwise else use this one
[UIView commitAnimations];