switch from one navigation Controller to another navigation View Controller - iphone

I am developing an application in which I am using two navigation Controllers , and uilocalNotification
first NavigationViewController N1 has two ViewControllers v1 and v2
second NavigationViewController N2 has two ViewControllers v3 and v4
Also , when application is in background , and if UILocalNotification appears and if I click on it , the application should detect which navigation Controller and which viewController is displayed and then switch to another navigationController's viewcontroller .
Ex:-
If v2 in N1 is displayed , then
after notification is clicked ,
then switched to v3 in N2 is displayed
How to do this ??

just paste this bellow methods in your AppDelegate.m file and call particular method when you want to change UINavigationController...
For Example: if you are in v2 of N1 and notification changed then call bellow method like bellow...
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setRootViewControllerN2];
use this bellow methods for switch navigation controller with animations..
1. setRootViewControllerN1 : this is for set RootViewController with N1 navigationController.
-(void)setRootViewControllerN1{
self.window.rootViewController = N1;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}
2. setRootViewControllerN2 : this is for set RootViewController with N2 navigationController.
-(void)setRootViewControllerN2{
self.window.rootViewController = N2;
[self.window makeKeyAndVisible];
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionFade];
[animation setDuration:0.5];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
kCAMediaTimingFunctionEaseInEaseOut]];
[[self.window layer] addAnimation:animation forKey:kAnimationKey];
}

Related

How can I load a view from left side?

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
This function load a view from right side. How can I Load a view from left side?
Here it is
CATransition *animation = [CATransition animation];
[[self navigationController] pushViewController:elementController animated:NO];
[animation setDuration:0.45];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[elementController.view layer] addAnimation:animation forKey:#"SwitchToView1"];
For this you have to #import <QuartzCore/QuartzCore.h>
don't think there is a readymade way to do that. You will have to animate the view yourself using animateWithDuration:delay:options:animations:completion: or animateWithDuration:animations:completion: (or any other animation methods) and change frames of your view accordingly so that it animates from the right side.
Hope this helps :)
if you already been pushed to a viewController you can use this:
[self.navigationController popViewControllerAnimated:YES]

Load a Navigation ViewController from bottom

I am having four ViewControllers , where the ViewControllers are loaded using the UINavigationController. I am able to switch to every ViewController one by one.
The thing is, since I am using the NavigationController all the ViewControllers are loaded either from the Left or from the Right. But I want to load the ViewController from the Bottom. I know I can use presentModalViewController to present the ViewController from the Bottom. But it is not equivalent to the Navigation Controller because , from the 4th ViewController, If I press one button , I need to come to the 1st ViewController.
How can I present a ViewController from the bottom in the NavigationController ?
Try this:
CATransition *animation = [CATransition animation];
[animation setDuration:2];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
SecondView *sObj=[[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:sObj animated:YES];
[[sObj.view layer] addAnimation:animation forKey:#"SwitchToView1"];
Use this may this will help you
[UIView beginAnimations:#"Hide Me" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:kAnimationDur];
subScroll.frame = CGRectMake(0,ksubScrollHideY,ksubScrollW,ksubScrollH);
clickPic.frame = CGRectMake(kButtonX,kButtonHiddenY,kButtonW,kButtonH);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
Happy Coding :)
after you create the viewController, instead of:
[self.navigationController pushViewController:blablabla animated:YES];
do:
[self presentModalViewController:blablabla animated:YES];
and it will come from the bottom.
to go back, just say:
[self dismissViewControllerAnimated:YES];

pushView animation in one page iPhone application?

i have a web based application with only one view controller. i have some shortcut buttons in my app which will load some urls. what i need is a push animation as like
pushViewController each time when i click the shortCut buttons.
i have only one UIView .
so, i have found the solution myself,
push like animation for any view
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[self.view layer] addAnimation:animation forKey:#"SwitchToView1"];
thanks for your feedbacks,

switching two views causes crash

XYZAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate];
CSelectorViewController *cPrice=[[CSelectorViewController alloc] initWithNibName:#"CSelectorViewController" bundle:nil];
[cPrice.view setFrame:CGRectMake(0, 20, 320, 480)];
[appdelegate.window addSubview:cPrice.view];
[self applyAnimation];
[cPrice release];
i am adding a view like this,not using navigationcontroller,since i have to switch two views top-bottom also.but when i am giving the [cPrice release]; the app crashes. but when i am not giving it in code... the static analyser is showing a warning..what is the right way to do this?
-(void)applyAnimation
{
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
XYZAppDelegate *appdelegate=[[UIApplication sharedApplication] delegate];
[[appdelegate.window layer] addAnimation:animation forKey:#"slideLeft"];
}
You're adding the view of cPrice to the window as a subview (which will implicitly retain the view), but you do nothing to preserve cPrice itself. You should make it a retained property or some such.

Partial page curl animation

I have a working transition using UIViewAnimationTransitionCurlUp however, I would like the animation to stop halfway through, much like the Maps application...Any thoughts on how to achieve this?
In iOS 3.2 and later, you can give your UIViewController a UIModalTransitionStyle of UIModalTransitionStylePartialCurl. From the UIViewController reference, we see
typedef enum {
UIModalTransitionStyleCoverVertical = 0,
UIModalTransitionStyleFlipHorizontal,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStylePartialCurl,
} UIModalTransitionStyle;
So an example use case would be:
UIViewController *viewController;
// …create or retrieve your view controller…
// Note: The modalPresentationStyle must be UIModalPresentationFullScreen,
// and the presenter must also be a full-screen view
viewController.modalPresentationStyle = UIModalPresentationFullScreen;
viewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
I found a solution to add an UIView to UIViewController using Animation block.
m_Container is an UIView who contain my view animation (self).
self is an UIView.
CAUTION : You need to have import QuartzCore
To present view with page curl animation you can use :
-(void)PresentView
{
[UIView animateWithDuration:1.0
animations:^{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.65;
[animation setRemovedOnCompletion:NO];
[m_container.layer addAnimation:animation forKey:#"pageCurlAnimation"];
[m_container addSubview:self];
;}
];
}
And when you want hide this view you can use :
-(void)HideHelpView
{
[UIView animateWithDuration:1.0
animations:^{
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setDuration:0.7];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
animation.type = #"pageUnCurl";
animation.fillMode = kCAFillModeForwards;
animation.startProgress = 0.35;
[animation setRemovedOnCompletion:NO];
[m_container.layer addAnimation:animation forKey:#"pageUnCurlAnimation"];
[self removeFromSuperview];
;}
];
}
The Maps partial curl is a private API. You can find details of how to use it in Erica Sadun's book The iPhone Developer's Cookbook, but you will get rejected from the App Store for using it.
Not sure if this will work, but the parameter to +setAnimationRepeatCount: can be a fraction.