I'm pushing a view controller that contains a tableiview onto my uinavigation controller:
CourseMenuViewController *mvc = [[[CourseMenuViewController alloc] initWithSlidingNavigationcontroller:self.slidingNavigationController] autorelease];
mvc.course = course;
[self.navigationController pushViewController:mvc animated:YES];
[self.navigationController setNavigationBarHidden:NO animated:NO];
So far so good, everything works as expected. My issue occurs when I watch the animation and see all of my table view rows animate down from the top of the screen as the view is animating in from the left. This makes it feel like the view is moving from the top-left corner to the bottom-right corner in a diagonal path.
My question is, how can I make the table view just appear instead of animating? I should add that all of my cells are static so I'm not waiting on any data from a NSFetchedResultsController or anything like that.
roronoa below put me on the right path, and here is the now working version:
CourseMenuViewController *mvc = [[[CourseMenuViewController alloc] initWithSlidingNavigationcontroller:self.slidingNavigationController] autorelease];
mvc.course = course;
CATransition *caTransition = [CATransition animation];
caTransition.duration = 0.35;
caTransition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
caTransition.delegate = self;
caTransition.type = kCATransitionPush;
caTransition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:caTransition forKey:nil];
[self.navigationController pushViewController:mvc animated:NO];
You have not mentioned details about your class CourseMenuViewController and initWithSlidingNavigationcontroller , but you can use the following to get the job done:-
CourseMenuViewController *mvc =[[CourseMenuViewController alloc] init];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[self.navigationController pushViewController:mvc animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
[mvc release];
you can have any type of animation that you want in the above code by changing the animation constants according to your need without having unwanted animations on your tableview.
Related
I want to create transition between view controllers like this.
https://www.dropbox.com/s/qatwqaq2mowocsg/Transitions%20Controller.gif?dl=0
I 've used the following code to create transition but cannot achieve following results.
self.settings = [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
CATransition* transition = [CATransition animation];
transition.duration = 0.4;
transition.type = kCATransitionPush;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.subtype=kCATransitionFromRight;
[[self navigationController].view.layer addAnimation:transition forKey:kCATransition];
[[self navigationController] pushViewController:self.settings animated:NO];
You can try this code :
self.settings = [self.storyboard instantiateViewControllerWithIdentifier:#"settings"];
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:0.80];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:
UIViewAnimationTransitionFlipFromRight
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:self.settings animated:YES];
[UIView commitAnimations];
Start from iOS7 you can custom the transition effect of system method pushViewController and presentViewController. For example if you need to custom the push effect there is a method in UINavigationControllerDelegate named
- (id<UIViewControllerAnimatedTransitioning> _Nullable)navigationController:(UINavigationController * _Nonnull)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController * _Nonnull)fromVC toViewController:(UIViewController * _Nonnull)toVC
add the custom animation to fromVC's view and show the toVC's view in proper time
While it's not a direct implementable chunk of code that represents THE ANSWER, this blog should get you through the steps to create your own custom transitions: http://blog.dadabeatnik.com/2013/10/13/custom-segues/
I am pushing a view controller whilst animating it so it flips. However, the animation is only applied to the view beneath the navigation bar, so the navigation bar hides for a few seconds then suddenly appears again. How can I apply the animation to the entire view, including the navigation bar?
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"OverviewiPad" bundle:nil];
OverviewViewController *overviewVC = [sb instantiateViewControllerWithIdentifier:#"OverviewViewController"];
overviewVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:overviewVC animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
My app is setup using a UINavigationController for all of the navigation. I am wanting to use a modal transition to present a specific view controller in the app. The thing is that I want to keep that new VC embedded inside of the navigation controller, but just that one view needs to use a modal animation rather than push.
How can I go about implementing this modal animation/transition on a single view controller within the UINavigationController?
Keep in mind that after this modal animation happens there will be buttons on that page that will proceed to work in line with a standard UINavigationController push animation.
ITviewViewController *vc = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"vc"];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:Nil];
Replace the pseudo code with your view controller names.
With iOS7, this is possible using the new custom transitioning API. You can find more information here: http://www.objc.io/issue-5/view-controller-transitions.html
You create an animation controller (interactive or otherwise), and pass it in the appropriate method of the navigation bar delegate. In your animation controller, you perform the custom animation using UIView animation API. In your case, the animation should perform a slide from bottom into place for forward animation, and slide from place to bottom for reverse animation. If you support interactive animation, you can even control the curve of the animation in relation to the finger slide.
Modal view by default is full screen. You need to change presentation style to show navigationBar
EDIT : This only works for iPad. For iPhone you can use MZformsheet or Kentnguyen to get semi modal behavior
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0,44/*navigation bar's height*/,height, width);//it's important to do this after
// use full screen height and width here
targetController.view.superview.center = self.view.center;
Use this line not presentModelViewController
[self presentViewController:vc animated:YES completion:Nil];
Maybe something like this will work for you (self is UINavigationController):
- (void)verticalPushViewController:(UIViewController *)controller
{
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.duration = 0.3;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.view.layer addAnimation:transition forKey:kCATransition];
[self pushViewController:controller animated:NO];
}
- (UIViewController *)verticalPopViewController
{
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
CATransition* transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.duration = 0.3;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
[self.view.layer addAnimation:transition forKey:kCATransition];
return [self popViewControllerAnimated:NO];
}
The simplest way.
To present
LaunchImageViewController *launchView = [self.storyboard instantiateViewControllerWithIdentifier:#"launchImage"];
[[UIApplication sharedApplication].keyWindow addSubview:launchView.view];
To close. I calling this inside presented(LaunchImageViewController).
[self.view removeFromSuperview];
I am presenting a view controller using the foll. code:
VC_B * b = [[VC_B alloc] init...];
[self presentViewController:b animated:YES completion:nil];
I am trying to animate appearance of the view controller: the incoming VC should slide down from top covering VC that is currently displayed. following this solution makes it work with one problem: current VC disappears before the incoming VC appears on the screen. Is there a way to resolve this? perhaps there is an alternative solution to achieve this effect.
Try this code :
CreateNewViewController *newViewController = [[CreateNewViewController alloc]initWithNibName:#"CreateNewViewController" bundle:nil];
CATransition *transition = [CATransition animation];
transition.duration = 0.05;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type =kCATransitionMoveIn;
transition.subtype =kCATransitionFromTop;
transition.delegate = self;
[self presentModalViewController:newViewController animated:NO];
[self.view insertSubview:newViewController.view atIndex:0];
[self.view.layer addAnimation:transition forKey:nil];
Hope this will help you .
Try the below code. You just need to call below method from the point where you want to display NewViewController. What you need to do is that you just need to change the OriginY of NewViewcOntroller's View Frame.
-(void)displayNewVC
{
YourNewViewController *newVC = [[YourNewViewController alloc] init];
CGFloat originY = -450;//set originY as you want to display newViewController from the Top to bottom with animation
//initially set originY out of the Frame of CurrentViewcontroller
newVC.view.frame = CGRectMake(orginX, originY, newVC.view.frame.size.width, newVC.view.frame.size.height);
/*Display View With Animation*/
originY = 300;
[UIView animateWithDuration:.3 animations:^{
//set new originY as you want.
newVC.view.frame = CGRectMake(orginX, originY, newVC.view.frame.size.width, newVC.view.frame.size.height);
} completion:NULL];
[currentViewController.view addSubview:newVC.view];
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
alarmViewController = [[AlarmViewController alloc] init];
[self.navigationController pushViewController:alarmViewController animated:YES];
[alarmViewController release];
[UIView commitAnimations];
I just want the viewcontroller flip like opening a book page,but it does not work like this.And I have a question that whether navigationController can animate this effect?
Since you are already putting the navigationController in an animation block. Mark animated:NO -
[self.navigationController pushViewController:alarmViewController animated:NO];
when we actually call pushViewController: we are setting the animated value to NO. This disables the Navigation Controller's default animation. Instead, the block of code uses the defined transition.