What is the simplest way to create a custom UIView animation transition? Most of the tutorials that pop up in a Google search are not recent. (I'm using XCode 4.5 version) In my current iPhone app I have the following code for my screen transitions:
[UIView beginAnimations:#"View flip" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.25];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[UIView commitAnimations];
I want something unique instead of the 5 or 6 built-in transitions. Any ideas or suggestions on where to start?
I think this is what you are looking for:
[UIView animateWithDuration:0.3 animations:^{
//Move frame or transform view
}];
Inside that block you can put arbitrary animation code.
Related
I have an UIView animation to move an object on the screen and I want the animation to be stopped (and the object to keep the position when the animation is stopped) when the object goes off the screen.
I want my object to always be visible, and to stop moving when it meets an edge of the screen. The target point may be anywhere.
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
self.MyObject.center = targetPoint;
[UIView commitAnimations];
I tried to fire a scheduled timer which check if the object is off screen but it seems that the position my object does not change.
Thanks for your help.
Below is the code sample if you are looking to animate the object from left to right edge of the screen.
CGRect objectFrame = self.MyObject.frame;
objectFrame.origin.x = self.view.frame.size.width-objectFrame.size.width;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[self.MyObject setFrame:objectFrame];
[UIView commitAnimations];
Hope it helps.
Cheers.
I want to hide my Splash_View In Page curl Style, so that it can move to another class.
Default.png
Any Idea or suggestion from experts would be welcome.
Try this code:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.window cache:YES];
[UIView commitAnimations];
Splash_Image_View.hidden = YES;
You'll need to make the splash image part of the main view to animate it. In your main view controller, set up an IBOutlet for a UIImageView, I'll call it splashImageView. In the MainWindow.xib file, drag in a UIImageView with your splash image on it and hook it up to the outlet. Then in the viewDidAppear of your main view controller .m file, you'll need to do something like this:
[UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{
splashImageView.hidden = YES;
} completion:NULL];
This will hide the splash view with a curl animation.
The simplest solution comes to mind is to load the same picture in your first [ViewDidLoad] and then doing something like this:
[UIView transitionWithView:self.view duration:0.4
delay:0.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
//hide splash here
}
completion:^(BOOL finished){
}];
I am working on a storybook app, i want to do the page curl like in the following video.
Demo Video
Can anyone tell me how to do exactly like this.
Update:
I want this page curling to support iOS 4.3+. UIPageViewController will work only on iOS 6.
You might want to consider UIPageViewController. It is quite useful in creating apps which use page curling animations. Here is the documentations link.
You can make use of the UIView's animation effect for this. I guess this should help you
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:contentView cache:YES];
[UIView commitAnimations];
where the contentView is the view where you are applying the animation. By varying the duration and animation curve you can modify your animation effect.
There are two ways of doing it:
The hard way, implement everything yourself (from scratch, with layers and masks and transforms and gradients) and a lot of headache.
the Easy way, read the documentation for UIPageViewController as suggested by #Zen. Its very useful and gives you the exact animation that you want (as shown in video). Or, using some third party code.
If you dont't have time constraint, then I will say, go the first way. You will learn a lot.
Cheers, have fun :)
EDIT
Here is the link to a sample app:
https://www.dropbox.com/s/x4qo2igrzvnkj16/CurlAnimationProject.zip
check it and tell me what you think.
SettingViewController *svc = [[SettingViewController alloc]initWithNibName:#"SettingViewController" bundle:nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[self.navigationController pushViewController:svc animated:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
As mentioned several time in the answers the UIPageViewController (apple documentation) is the thing you should be looking at.
The implementation is fairly straightforward, the controller uses 2 delegates
datasource : controlling the content to display (your pages) through 2 main methods
delegate : controlling its behaviour
It implements the swipe gesture for scrolling from page to page and can feature a page control at the bottom of your view.
For transitioning from page to page, you can either set a scroll animation (nice for photo / portfolios type) or the page curl you are looking for.
You can make page curl/flip effect by
For landscape mode:
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:contentView cache:YES];
[UIView commitAnimations];
For portrait mode:
[UIView beginAnimations:#"Curl" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlLeft forView:contentView cache:YES];
[UIView commitAnimations];
I have this code:
- (IBAction)open:(id)sender{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
[splash removeFromSuperview];
[UIView commitAnimations];
}
I have an imageView "splash" and I remove it with the IBAction, but my problem is that it remove splash from left, and I want to remove it from right, what can I do?
There is no UIViewAnimationTransitionCurlRight nor Left in the iOS.
For IOS5 projects you can use the new UIPageViewController that is working similar to the iBooks App.
you can see my answer here with links - Page curl - Leaves Project - Interaction elements
For other versions you can find here a work around to set this curl:
I want to use animation to imageview using UIanimationtransitioncurl right or left. Is it possible?
Good Luck
I have this code:
when image change alpha from 0.00 to 1.00 it is imediately and not in 3 seconds, why?
- (void) startAnimation{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:1.00];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:3];
[successView setAlpha:0.00];
[UIView commitAnimations];}
Both animations are run in the same run cycle (that's how UIView animations work—all animations in one run cycle are "concatenated." You'll need to use
[UIView setAnimationDelay:3.0];
On the second animation.
Example Code
There are two ways to do this—using the standard begin/commit animations, or using the blocks method. This example uses the begin/commit animations code, which is what you have. The issue is because the animations are being concatenated, and without going into CA, the standard animation behavior is for one to be "forced" to end before the other runs. It has to do with run loops; Building Animation-Driven Interfaces from WWDC 2010 goes into depth about this. But the code to do what you want looks like this:
- (void)fadeOut {
[UIView beginAnimations:#"Animation2" context:NULL];
[UIView setAnimationDuration:3];
[self.testView setAlpha:0.00];
[UIView commitAnimations];
}
- (IBAction)animate {
[UIView beginAnimations:#"Animation1" context:NULL];
[UIView setAnimationDuration:3];
[self.testView setAlpha:1.00];
[UIView commitAnimations];
[self performSelector:#selector(fadeOut) withObject:nil afterDelay:3.0];
}
You have to force it to break up the run loop, basically. The key thing to remember is that animations are not executed sequentially, as you might expect code to be.
The blocks-based code looks like this. Note that I'm using the autorepeat option, which automatically repeats the animation. Note though that in the animation, you are setting a property, so by default after the animation completes the view will go back to being visible. Therefore, you have the set the property again to zero in the completion block.
- (IBAction)animate {
[UIView transitionWithView:self.testView duration:3.0 options:UIViewAnimationOptionAutoreverse animations:^{self.testView.alpha = 1.0;} completion:^(BOOL finished) {self.testView.alpha = 0.0;}];
}
Hopefully this helps!