I'm able to implement the concept of childviewcontroller in my PhoneGap project.
Now when I click on any link of my app, that opens in childviewcontroller successfully.
Here is a line that opens the page in clildbrowser
[super.viewController presentModalViewController:childBrowser
animated:YES ];
Now I want to open childBrowser as a pushViewController. Currently it comes from bottom to top but i want this to open from left to right.
Is there any way? Replacing presentModalViewController to pushViewController fails.
presentModalViewController and pushViewController ar every different in concept.
If you just need to change the animation, you might want to do something like this:
childBrowser.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//childBrowser.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//childBrowser.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//childBrowser.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[super.viewController presentModalViewController:modalViewController
animated:YES];
or simply use traditional animations (code needs adapting):
UIViewController *controller = [[[MyViewController alloc] init] autorelease];
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[navController presentModalViewController: controller animated: NO];
[UIView commitAnimations];
Related
I am updating an old app to the new adaptive size way of doing things and having difficulty getting a popover with a navigation controller to work.
My goal: I want to be able to open a popover from a button when the app is either compact and regular horizontal. The popover has a tableview and uses a navigation controller to push view controllers when the user touches a row on the table. I can get the popover to open correctly, but I can’t figure out who to make the pushes work.
Here’s the code that opens the popover:
OptionsController *vc = [[OptionsController alloc] initWithNibName:#"OptionsView" bundle:nil];
vc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popover = [vc popoverPresentationController];
popover.delegate = self;
[self presentViewController:vc animated: YES completion: nil];
popover.permittedArrowDirections = UIPopoverArrowDirectionUp; // change as necessary
popover.sourceView = self.view;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popover.sourceRect = popoverRect;
This code correctly opens a popover in either compact or regular size.
In the OptionsController’s didSelectRowAtIndexPath method, I have this(controllersArray is an array of UIViewControllers, each of which corresponds to a row in the table):
UIViewController *nextController = [self.controllersArray objectAtIndex: [indexPath row]];
[self.navigationController pushViewController:nextController animated:YES];
All this executes, but no push occurs, so the next view never appears.
I clearly am not understanding something about using the UIViewController’s navigationController, or how to install a navigationController to make this work. After three or four days of digging around to try to understand how to make this work, I'd appreciate any insights, or links to documentation about how to do this. Thanks in advance.
Crud - this has a very easy answer. Just took me thinking a different way and digging through Larcerax's comments. Here's how to make this work:
OptionsController *vc = [[OptionsController alloc] initWithStyle:UITableViewStylePlain];
vc.title = #"Options";
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController: vc];
nc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popover = [nc popoverPresentationController];
popover.delegate = self;
[self presentViewController:nc animated: YES completion: nil];
popover.permittedArrowDirections = UIPopoverArrowDirectionUp; // change as necessary
popover.sourceView = self.view;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popover.sourceRect = popoverRect;
The difference is that I create the UINavigationController in the usual manner...
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController: vc];
...set the navigationController's presentation style to popover, then get the popoverPresentationController from the navigationController - before I was doing those two methods on the UIViewController.
nc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popover = [nc popoverPresentationController];
Finally, I present the navigationController:
nc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popover = [nc popoverPresentationController];
This approach presents a popover, in compact and regular horizontal sizes, that contains navigation controller functionality: just what I wanted.
Thanks again to Larcerax whose answer wasn't what I needed, but made me re-think what I was doing in a different way. As usual, StackOverflow comes through.
Here's what you should try. I use about 10-40 navigation controllers per app for the apps I work on and I've had this same sort of issue, I've not used popovers, but I've subclassed the crap out of navigation controllers and view controllers to have encountered your same problem. The thing is that if you do this:
UIViewController * ff = [UIViewController new]
[self presnetViewController:ff ... blah blah blah
There is apparently NO navigation system attached to the modal view controller and therefore you can't navigate to anything else, you can only close the modal and move on. So, this is what I do to resolve this and it works everytime, well it works everytime for UIViewControllers, give it a shot
see the following, it's not for popovers, but the principle is the same:
NSHTermsOfServiceViewController * pvc = [NSHTermsOfServiceViewController new];
UIBarButtonItem * backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"exit-button"] style:UIBarButtonItemStylePlain target:self action:#selector(backerPressed)];
NSHNavigationController * ssf = [[NSHNavigationController alloc] initWithRootViewController:pvc];
[[pvc navigationItem] setLeftBarButtonItem:backBarButtonItem];
[[self navigationController] presentViewController:ssf animated:true completion:nil];
NSHTermsOfServiceViewController <== is a subclass of another subclass of a UIViewcontroller, it's basically a UIViewController on steroids, that's all
NSHNavigationController is a UINavigationController that is subclassed and pumped up on steroids for animations
The flow is this:
create a viewController
create a new UINavigationController
Set the view controller you created in step 1 as the root view controller of the navigation controller created in step 2
present the NAVIGATION CONTROLLER, not the UIViewController, you can present this navigationController from a view controller like so ..
v
[self presentViewController:ssf animated:true completion:nil];
or you can present it from the current view controller's navigation controller which is what I prefer, like so:
[[self navigationController] presentViewController:ssf animated:true completion:nil];
Your code, modified, the only problem is that I don't know if you can present a UIPopOverViewController by rooting it inside a navigation controller
OptionsController *vc = [[OptionsController alloc] initWithNibName:#"OptionsView" bundle:nil];
UIPopoverPresentationController *popover = [vc popoverPresentationController];
UINavigationController * stuff = [[NSHNavigationController alloc] initWithRootViewController:popover];
stuff.modalPresentationStyle = UIModalPresentationPopover;
stuff.delegate = self;
[self.navigationController presentViewController:stuff animated: YES completion: nil];
popover.permittedArrowDirections = UIPopoverArrowDirectionUp; // change as necessary
popover.sourceView = self.view;
CGRect popoverRect = [self.view convertRect:[sender frame] fromView:[sender superview]];
popover.sourceRect = popoverRect;
Yep, my bad, doesn't work for popover, I just tried it
So, with that said, is it absolutely necessary to use a popover? Why are you using this and now just a UIViewcontroller that you reconfigure to look like a popover and then you have what you need?
Here's this, I just tried it with the Ipad simulator, and it allowed a push, just as it should have.
NSHLoginViewController * pvc = [NSHLoginViewController new];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:pvc];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
UIView * stuff = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 1000, 1000)];
[self.view addSubview:stuff];
[popover presentPopoverFromRect:[[self contentView] nameField].frame inView:stuff permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
this: [[self contentView] nameField].frame is just a uitextfield, nothing special, that's all, and the method above presented the login viewcontroller, when I put in my credentials, I pressed log in and it pusehed the next viewcontroller as it normally would, there's probalby something wrong with the touches being intercepted by your uitableview or whatever, perhaps not, but this method did work for me.
I m developing a E-commerce mobile application in iOS. I need to know how to move from one UIViewController to another UIViewController with slide animation from top to bottom.
I am using Storyboard.
App needs to works in ios6 and ios7.
Below is the code i used for tranitioning UIViewController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MenuViewController *viewController =
(MenuViewController *)
[storyboard instantiateViewControllerWithIdentifier:#"menupage"];
[self.navigationController pushViewController:viewController animated:NO];
Below is the code I tried for a turn page effect and it worked fine. I need the same thing as below for a slide top to bottom
[UIView beginAnimations:#"View Flip" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.navigationController.view cache:NO];
[self.navigationController pushViewController:viewController animated:YES];
[UIView commitAnimations];
The another method
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MenuViewController *viewController = (MenuViewController *)[storyboard instantiateViewControllerWithIdentifier:#"menupage"];
MenuViewController *viewController1 = (MenuViewController *)[storyboard instantiateViewControllerWithIdentifier:#"menupage"];
[self.view addSubview:viewController.view];
viewController.view.frame=CGRectMake(0,480,320,480);
[UIView animateWithDuration:1
animations:^{
viewController.view.frame=CGRectMake(0,0,320,480);
}
completion:^(BOOL fin){
if (fin)
{
[self.navigationController pushViewController:viewController animated:NO];
[self.navigationController pushViewController:viewController1 animated:NO];
}
}];
Here i get animation in success manner.But i need to load same view controller twice.One is for animation and another one is for normal ViewController Load.If i didnt load second method i get some problem in nextviewController button actions.
Thanks in Advance
Sam.P
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.navigationController.view cache:NO];
instead of using UIViewAnimationTransitionCurlUp use UIViewAnimationCoverVertical
or simply without any view animations, just change a single line.
[self.navigationController presentViewController:viewController animated:YES completion:NULL];
FYI #MaheThiru the push only gives u to and fro transition and for push u need navigation controller. the other transitions like coververtical, pagecurl, crossdissolve and fliphorizontal are provided by modal transition(without navigation controller) which we write as
[self presentViewController:viewController animated:YES completion:NULL];
and i got a small doubt here y r u writing
animated:NO
change it to
animated:YES
maybe it will solve the problem. try it once.
Happy coding
I am woking on a project where i have to show a custom alert view similar to
I found, that customising UIAlertView is a wrong approach! So the way to achieve it is using UIView, that would Pop-in and Pop-out like UIAlertView using animation.
I have also seen some SOs [question]: How can I customize an iOS alert view? and [question]: UIView Popup like UIAlertView
Still i am facing problem, like AlertView not appearing. Can anyone just share some good tutorial on the same.
//Thanks
The system UIAlertView creates its own UIWindow so it can float above your normal UIWindow. You might want to try that approach. If you do, you might find some useful hints in this answer about using extra UIWindows.
You can use a Modal View Controller
A modal view controller is simply a UIViewController class that is presented modally.
To present a view controller in a modal fashion, you can use the method:
- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated;
Change the Frame as a 50% of view and you can apply different Animations to it for representation.
Here are the available modal transition styles
yourModelViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
yourModelViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
yourModelViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
yourModelViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
Example Code:
UIViewController *controller = [[MyViewController alloc] init];
controller.frame = yourFrame;
UIViewAnimationTransition trans = UIViewAnimationTransitionCurlUp;
[UIView beginAnimations: nil context: nil];
[UIView setAnimationTransition: trans forView: [self window] cache: YES];
[self.view presentModalViewController: controller animated: NO];
[UIView commitAnimations];
I'm trying to add subview with UIViewAnimationCurveEaseIn into MyMainView.
I have two UIView in my ViewController.xib file.
There is a one button in MainView , when I clicked that button, I want to call another view with UIViewAnimationCurveEaseIn.
In some of iOS app, the new view appear from the below with slide.
I think that's used with UIViewAnimationCurveEaseIn.
I also want to do like that.
If I'm wrong,please guide me how to do that.
Or where can I read that function?
Try this:
AViewController *aVC = [[AViewController alloc]initWithNibName:#"AViewController" bundle:nil];
//[self.navigationController pushViewController:aVC animated:NO];
[UIView transitionFromView:self.view toView:aVC.view duration:0.5f options:UIViewAnimationCurveEaseIn completion:^(BOOL doneDissolve){
[self.view addSubview:aVC.view];
}];
[aVC release];
So, i have a UITabbarController with an UINavigationController in it. On the press of a button, i would like to bring in another UINavigationController, animating it like when using presentModalViewController:animated:, but i do not want it to hide the TabBar.
Is there anything in UIKit (3.1.3 and later) that i could use for this or will i have to do the animating myself?
Just test the code, maybe you need to set the navigationController as property if you need do sth like pushViewController:animated:.
UIViewController * aViewController = [[UIViewController alloc] init];
[aViewController.view setFrame:self.view.frame];
[aViewController.view setBackgroundColor:[UIColor redColor]];
UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:aViewController];
[aViewController release];
[navigationController.view setFrame:CGRectMake(0.0f, 480.0f, 320.0f, 480.0f)];
[self.navigationController.view addSubview:navigationController.view];
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionCurveLinear
animations:^{
[navigationController.view setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)];
}
completion:nil];
[navigationController release];
The only way by default to present something from the bottom up is the presentModalViewController. You can actually override the animations for your navigationController, but it isn't something you can achieve just by calling a different method, you will have to create your own, and handle the animations too.
Another way to possibly cheat this would be to reload your tabBar in the view you are presenting modally, but that could get messy.