Add Slide In from Left to Right animation(transition) in addSubView - ios

I Try to imitate the NavigationViewController, very similar to default MailApp in iPhone
When clicking on a Mail summary, it should slide-in the mail details, and when BACK button is clicked, Mail Summary view is to be slided-in back again.
This is what I have to animate the transition from Summary To Detail (removeFromSuperView)
CGRect temp = self.view.frame;
temp.origin.x = 300;
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationCurveEaseOut
animations:^{
self.view.frame = temp;
}completion:^(BOOL finished){
[self.view removeFromSuperview];
}];
This is what I have to animate the transition from Detail To Summary (addSubview)
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionFromRight;
transition.subtype = kCATransitionFade;
[parentView.layer addAnimation:transition forKey:nil];
[parentView addSubview:myVC.view];
Now, that My First part of code is working well! Where-as the second part, I am just able to achieve the Fade-in animation. How can I bring in the slide transition?

I just need to choose kCATransitionPush type for my CATransition
CATransition *transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[parentView.layer addAnimation:transition forKey:nil];
[parentView addSubview:myVC.view];
Update for Swift:
let transition = CATransition()
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
parentView.layer.add(transition, forKey: nil)
parentView.addSubview(myVC.view)

Or you could check out : HorizontalSlide Segue (just google it I cant get the link, on mobile) its a great sliding transition that is simply a segue that you add from view A to B....
On a side note, if this is in a nav controller, a push or a pop should have a slide animation by default...

Related

How to navigate to another viewcontroller with PUSH style from UITabBarController page

First of all, I'm a beginner. forgive me for this stupid question.
I make two child pages usingUITabBarController, the first page including aUIButton, and alsl I make a another page (DetailPage). I connectted the button andDetailPage with segue. but the style of segue cannot be setted to push.(this will trigger a error , push style only used forUINavigatorController).
So, when I click the button , how to navigate to DetailPage with PUSH style?
I try a new method, UsingUINavigatorController to manage first page and DetailPage, and then make thisUINavigatorController embed intoUITabItem. when I finish this, I can navigate to DetailPage with push style. But another question occured, when navigating DetailPage , the TabBar is always stay the bottom of page. I wanna allUITabBarController will be pushed to left side.
The effect what I want like this picture:
How can I optimize my code?
Implement delegate(UITabBarControllerDelegate) method like this :
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
NSArray *tabViewControllers = tabBarController.viewControllers;
UIView * fromView = tabBarController.selectedViewController.view;
UIView * toView = viewController.view;
if (fromView == toView)
return false;
NSUInteger fromIndex = [tabViewControllers indexOfObject:tabBarController.selectedViewController];
NSUInteger toIndex = [tabViewControllers indexOfObject:viewController];
[UIView transitionFromView:fromView
toView:toView
duration:0.3
options: toIndex > fromIndex ? UIViewAnimationOptionTransitionFlipFromLeft : UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished) {
if (finished) {
tabBarController.selectedIndex = toIndex;
}
}];
return true;
}
This is for flip animationJust change animation
For Push :
CATransition* transition = [CATransition animation];
[transition setDuration:0.3];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[transition setFillMode:kCAFillModeBoth];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:transition forKey:kCATransition];
For Pop :
CATransition* transition = [CATransition animation];
[transition setDuration:0.3];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[transition setFillMode:kCAFillModeBoth];
[transition setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[view.layer addAnimation:transition forKey:kCATransition];
Now Its up to you, best of luck....

UINavigationBar fades when pushing/popping

I am using the old (pre-iOS7) push/pop animation by using the method described here:
#implementation UINavigationController (Retro)
- (void)pushViewControllerRetro:(UIViewController *)viewController {
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.layer addAnimation:transition forKey:nil];
[self pushViewController:viewController animated:NO];
}
- (void)popViewControllerRetro {
CATransition *transition = [CATransition animation];
transition.duration = 0.25;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.layer addAnimation:transition forKey:nil];
[self popViewControllerAnimated:NO];
}
#end
My problem is that iOS7 seems to fade the UINavigationBar of the previous view controller when pushing a new view controller. Normally this looks fine because iOS 7 is dragging the views on top of each other. But when I am using the pre-iOS7 animation it gives me a short flash, because the navigation bar fades while the new view it getting pushed in from the right side.
Is there a way to disable the fade animation on the navigation bar?

Unable to change the popviewcontrolleranimation

I am trying to change the navigationController push and pop animation like presentModalView and dismissModalView animation.
I am successfully change the push view animation by using the below code. For changing push animation is working fine. This code is shows the view from bottom to top animation(for push view).
CATransition *transition = [CATransition animation];
transition.duration = 0.4f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController pushViewController:locationObj animated:NO];
But When I am trying to change the pop view animation by using the below code. I am unable to get the top to bottom animation(for pop view).
CATransition *transition = [CATransition animation];
transition.duration = 0.4f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
Please can some one help me.
Tested Code:
CATransition *transition = [CATransition animation];
transition.duration = 0.4f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//Pop Animation
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition forKey:nil];
[self.navigationController popViewControllerAnimated:NO];
//Push Animation
//transition.type = kCATransitionMoveIn;
//transition.subtype = kCATransitionFromTop;
//[self.navigationController.view.layer addAnimation:transition forKey:nil];
//[self.navigationController pushViewController:viewControllerToBePushed animated:NO];

Multiple fades in a CATTransition

I'm using a CATransition to create a fade effect on the pushViewControllerAnimated of a UINavigationViewController. This worked out fine with the following code:
CATransition* transition = [CATransition animation];
transition.duration = 0.5;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;
[navController.view.layer addAnimation:transition forKey:kCATransition];
[navController popViewControllerAnimated:NO];
[navController pushViewController:nieuweDetailPagina animated:NO];
But because my views are very similar I would like to fade to white in between or show a white flash.
Is it posible to do it in the same transition or do I have to creat a UIView with a white background and start a simultanious animation?
Cheers!

Showing pushviewcontroller animation look like presentModalViewController

Is it possible to show pushViewController animation look like presentModalViewController but that has background functionality of pushViewController?
If you want to a fade animation, this approach works.
CATransition* transition = [CATransition animation];
transition.duration = 0.3;
transition.type = kCATransitionFade;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
[self.navigationController pushViewController:gridController animated:NO];
Try this :
UIViewController *yourViewController = [[UIViewController alloc]init];
[UIView beginAnimations: #"Showinfo"context: nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController: yourViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];
For display PushViewConttroler animation as Present below code is working,
For Push
ViewController *VC = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewController"];
CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromTop;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController pushViewController:VC animated:NO];
And for POP
CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionReveal;
transition.subtype = kCATransitionFromBottom;
[self.navigationController.view.layer addAnimation:transition
forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
There is 1 issue though, that its display light black background when its going up/down,
Working on that, As soon as its done post new code here.
For All Trying in Xamarin (C#) equivalent Code
From Answer by #hardik Thakkar above, Has the issue of Black backgound during animation, rest all good.
For POP
CATransition transition = CATransition.CreateAnimation();
transition.Duration = 0.4;
transition.Type = CAAnimation.TransitionReveal;
transition.Subtype = CAAnimation.TransitionFromTop;
this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));
For Push
CATransition transition = CATransition.CreateAnimation();
transition.Duration = 0.4;
transition.Type = CAAnimation.TransitionReveal;
transition.Subtype = CAAnimation.TransitionFromBottom;
this.NavigationController.View.Layer.AddAnimation(transition, nameof(CATransition));
You should consider doing something like:
ViewController *myVC = [[ViewController alloc] initWithFrame:OFF_SCREEN];
[navigationController pushViewController:myVC animated:NO];
where OFF_SCREEN is some CGRect below the screen, like (0, 481, 320, 480). Then use an animation block to adjust the viewcontroller's view's frame.origin to be (0, 0). You would probably want to do the animate block in viewDidLoad or viewDidAppear.

Resources