I'm trying to get my ViewController to slide from Left to Right at the same speed as the standard PushViewConrtoller, I'm not using a NavBar and don't want to use Modal, is there a simple way to do this, I've seen a lot of variations on different threads, but none of them work correctly!
I'm using a Navigation Controller with the following code for my Push right...
- (IBAction)launch1990:(id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"1990"];
[self.navigationController pushViewController:vc animated:YES];
}
UIStroryBoard when you push view controllers, or segues, it doesn't let you customize too much. What I ended up doing was override the perform method and used QuartzCore Animations to customize our transitions. I subclassed UIStoryBoardSegue and overwrote the perform function.
Below to customize for Push or Pop then for Segues. (For segues remember to change the class to the custom class in IB).
To do it from a normal pop or push (this does cross fade animation, adjust it for yours):
#import <QuartzCore/QuartzCore.h>
- (IBAction)launch1990:(id)sender {
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"1990Storyboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"1990"];
[self.navigationController pushViewController:vc animated:NO];
}
To do it from segue:
//ZHCustomSegue.h
#import <Foundation/Foundation.h>
#interface ZHCustomSegue : UIStoryboardSegue
#end
// ZHCustomSegue.m
#import "ZHCustomSegue.h"
#import "QuartzCore/QuartzCore.h"
#implementation ZHCustomSegue
-(void)perform {
UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
UIViewController *destinationController = (UIViewController*)[self destinationViewController];
CATransition* transition = [CATransition animation];
transition.duration = .45;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionFade; //kCATransitionMoveIn; //, kCATransitionPush, kCATransitionReveal, kCATransitionFade
//transition.subtype = kCATransitionFromLeft; //kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom
[sourceViewController.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[sourceViewController.navigationController pushViewController:destinationController animated:NO];
}
#end
Use CATransition with subtype: kCATransitionFromLeft
CATransition *transition = [CATransition animation];
transition.duration = .3;
transition.type = kCATransitionMoveIn;
transition.subtype= kCATransitionFromLeft;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
Do the normal navigation vc push, but beforehand:
vc.navigationBar.hidden = YES;
Related
This is what i have so far. What I am trying to do is make the starting view (startUpView) to switch to the other view (creatNewGameViewController) by sliding down the screen with the new view. All it does now is switch views normally, but i really want that sliding effect. If anyone can spot the error in my code it would be much appreciated. Thanks
#import "CreateNewGameViewController.h"
#synthesize createNewGameViewController;
UIButton *mainCreateGame = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[mainCreateGame addTarget:self
action:#selector(goToCreateGameViewController)
forControlEvents:UIControlEventTouchUpInside];
[mainScroll addSubview:mainCreateGame];
mainCreateGame.frame = CGRectMake(65, 10, 190, 60);
-(void)goToCreateGameViewController{
CreateNewGameViewController *newGame = [[CreateNewGameViewController alloc]initWithNibName:#"CreateNewGameViewController" bundle:nil];
self.createNewGameViewController = newGame;
CATransition *transition = [CATransition animation];
transition.duration = 2;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionMoveIn;
CATransition *transition1 = [CATransition animation];
transition1.duration = 2;
transition1.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition1.type =kCATransitionMoveIn;
transition1.subtype =kCATransitionFromTop;
transition1.delegate = self;
[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil];
transition1.subtype =kCATransitionFromTop;
transition1.delegate = self;
[self presentModalViewController:newGame animated:NO];
[self.view insertSubview:newGame.view atIndex:0];
[createNewGameViewController.view.layer addAnimation:transition1 forKey:nil];
[newGame release];
UIView has a class method called transition from view to view animated, check if that helps and tell me how it was :)
UiView
one piece of advice, you should really be using a navigation controller, a storyboard or something like it to do that kind of view transitions because is the proper way to do.
I want page curl like animation when I push another view. I don't need the default one.
Can I push view with custom animation? I have image sequence.
How can we do that? Help me, please!
You can do this using QuartzCore framwork.
first, #import and before push view controller add this code.
Hope you are OK!
YourViewController *viewControlle = [[YourViewController alloc] init];
CATransition* transition = [CATransition animation];
transition.duration = 1.0;
transition.type = #"pageUnCurl";
transition.subtype = kCATransitionFromRight;
transition.timingFunction = UIViewAnimationCurveEaseInOut;
[self.navigationController.view.layer
addAnimation:transition forKey:kCATransition];
[self.navigationController
pushViewController:viewControlle animated:NO];
the code below implement the switch between two view in a cube animation .
UIViewController* viewCtrl = [[UIViewController alloc] init:book];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube";
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:viewCtrl animated:YES];
[viewCtrl release];
but, if the view don't belong to self.navigationController, how to do switch in cube animation between two view controller, and then how to scale the current view controller's view in the same time? thanks very much
This worked for me:
-(IBAction)animate:(id)sender {
NSLog(#"animate");
CATransition *transition = [CATransition animation];
transition.delegate = self;
transition.duration = 0.8;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
NSString *types[4] = {#"cube", #"rippleEffect", #"cube", #"alignedCube"};
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromRight};
transition.type = types[0];
transition.subtype = subtypes[1];
[self.view.layer addAnimation:transition forKey:nil];
SecondView *_secondViewController = [[SecondView alloc]initWithNibName:#"secondView" bundle:nil];
self.secondViewController = _secondViewController;
_secondViewController = nil;
[[[self view] layer] addAnimation: transition forKey: nil];
[[self view] addSubview: [self.secondViewController view]];
}
-(void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag{
[self.view release];
}
I'm wondering if there is any chance to create a custom transition animation between Views, as a "cube":
http://www.pendrivelinux.com/wp-content/uploads/pdl-cubed.jpg
I've took a look for some example, without any success, do you know some, is even possible?
Thanks
UIViewController* viewCtrl = [[UIViewController alloc] init];
CATransition *transition = [CATransition animation];
transition.duration = 1;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = #"cube"; //Note: undocumented API, will probably cause App Store rejection
transition.subtype = kCATransitionFromLeft;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:viewCtrl animated:YES];
[viewCtrl release];
It should be possible. You will need to have 2 views and a bit of Core Animation 3D transforms.
Right now when I use [self.navigationController setNavigationBarHidden:NO animated:YES];
The navigation bar flies in from right to left, is there a way to drop it down top to bottom?
Give this a go:
CATransition *transition = [CATransition animation];
transition.duration = kAnimationDuration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:tableViewController animated:YES];
Worked great for me.
Source: http://www.iphonedevsdk.com/forum/iphone-sdk-development/25045-navigation-controller-custom-animation.html