Form Sheet Modal View Animations - iphone

I have UIModalPresentationFormSheet views appearing in my app. Some of them appear from the Right some from the Bottom and the dismissing seems random. Some disappear to the Bottom some go Left some go Up. Is there a way to set the direction they appear from and dismiss to?
Code I use to present (this same code, just different viewcontroller being presented, called from the same view controller has varying animations for different modal views):
MyViewController *newModalView = [[MyViewController alloc] init];
newModalView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:newModalView animated:YES];
Then in the modal view I call this to dismiss it:
[self dismissModalViewControllerAnimated:YES];

This is a known bug and is being worked on by apple.

Try something like this:
newModalView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

All the transition Styles:
newModalView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
newModalView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
newModalView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

Related

UIModalPresentationCurrentContext with Transition?

I am trying to modal present a view controller like below:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"addPopover"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:YES];
Now using UIModalPresentationCurrentContext means I can present this view with a transparent background and see my other view behind the new one. However, it stops me from being able to present it with a transition.
Any ideas why? Or how I can get around this? Thanks.
I was able to accomplish this by setting modalPresentationStyle = UIModalPresentationCurrentContext on the rootViewController of my UIWindow, IF I haven't presented any new full screen viewControllers on top of this rootViewController. I did something like this:
UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
I've tried this with both a UINavigationController as my window's rootViewController and various other custom view controllers. It seems as long as the window's rootViewController knows what's going on, any sub-viewControllers can call presentViewController:animated:completion: without blacking-out the underlying view.
However, let's say you present another viewController on top of your window's rootViewController. And this new viewController is presented with modalPresentationStyle = UIModalPresentationFullScreen (ie. takes up the screen), then you have to call modalPresentationStyle = UIModalPresentationCurrentContext on that top-most viewController.
So to recap:
If you have UINavigationController -> UIViewController(s) (they could be pushed and popped in and out), then you set modalPresentationStyle = UIModalPresentationCurrentContext on the UINavigationController.
If you have UINavigationController -> UIViewController -> new-UIViewController (with modalPresentationStyle set to UIModalPresentationFullScreen), then you set modalPresentationStyle = UIModalPresentationCurrentContext on the new-UIViewController.
Hopefully this works for you guys as well!
Full screen modals aren't supposed to allow you to see the under layer. Annoying I know.
From your code I'm assuming that "addPopover" is actually a full screen view, where you have your content as a subsection while the rest is transparent.
Try this:
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:vc animated:YES completion:NULL];
Note: I'd recommend adding a low alpha background color to let the user know that they can't interact with the rest of the view when you pop this over top...
Mr. T's suggestions worked nearly perfectly, you just lose the transition animation on the presented viewcontroller
Since it is also setting the appDelegates rootviewController's presentation style, it will also remove the transition animations for any views presented from that point.
My fix was to return the AppDelegates rootViewController's presentation style back to it's default whenever the viewcontroller is closed that I needed the transparent background on
I have a button that dismisses the presentedViewController, in that I also set the presentation style of the rootViewController back to default using:
UIViewController *rootViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
I hope that helps anyone else getting stumped on this problem.

How to insert a subview with xib?

I'm confused something fierce over having multiple views. I simply want to have a button on my main view that activates a new view, which in turn would have an (x) button which goes back to main view. For the life of me, I can't figure out how to do this with two separate .xib files. How might this be done?
Thanks!
It might be easiest to just use the utility application as a template.
From there, you can see how you would load view controllers and nibs in order to bring up the new view followed by how you would exit it.
I actually solved it by doing it this way:
NewViewController *new = [[NewViewController alloc] initWithNibName:#"NewViewController" bundle:nil];
new.delegate = self;
new.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:new animated:YES];
[new release];
You are using a navigation controller, right?
On the IBAction associated with a button tap on the main view, put
NewViewController *newView = ... // [alloc - init your view here if you haven't already]
[self.navigationController pushViewController:newView animated:YES];
And on the button on newView,
[self.navigationController popViewControllerAnimated:YES]

Three20 TTLauncher Issues

So, I'm having some issues with my implementation of the Three20 TTLauncherView. I am using their code, not a fork (although I have heard of rodmaz's version), and I can't get it to work properly. This is what my app looks like.
alt text http://img709.imageshack.us/img709/8792/screenshot20100715at409.png
I removed the icon image, that's not the issue. The issue is, at the top there is no Navigation bar at all, and I believe also causes the white strip at the bottom, which appears to have the same dimensions as a Nav Bar. I've spent quite a while looking through their code and can't figure this out at all. It looks like their Navigation bar (as seen in their Catalog example app) stems from the TTTableViewController, or something further up. However, my app starts like the Facebook app does, not into a table, but into the TTLauncherView. So... how do I get the Navigation bar into my TTLauncher view, if it goes "App Delegate -> TTLauncherView Subclass"
Thanks for your help!
Edit:
Added the code I used. I put this in my app delegate, wrapping my first view with the UINavigation Controller, and it worked just as I wanted!
MainViewController *aController = [[MainViewController alloc] initWithNibName:nil bundle:nil]; //my Main view
self.mainViewController = aController;
[aController release]; //release for Memory Management
self.mainViewController.view.frame = [UIScreen mainScreen].applicationFrame;
UINavigationController *navigationController = [[UINavigationController alloc] init];
[navigationController pushViewController:self.mainViewController animated:NO]; //Gets the main view on the screen
[window addSubview:navigationController.view];
You simply wrap the view with a navigation bar before you push the new view. As an example, here is a snippet of my code where I present a modal view controller with a navigation bar.
- (IBAction) showNewNavView: (id) sender
{
// Present it as a modal view and wrap the controller in a navigation controller to provide a navigation bar for the Edit and Save buttons
ModalViewController *addController = [[ModalViewController alloc] initWithNibName:#"ModalViewController" bundle:nil];
addController.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[addController release];
}
If you want to add any buttons or set the title of it, you need to do that in the viewDidLoad method of the view that you are pushing (i.e. your TTLauncher view)

presentModalViewController NOT animating when showing a TTMessageController

I have a subclass of TTMessageController that shows ... BUT it is not animated even though it should be. The code that displays the modal view looks like this (where PostToWebMessageController is the subclass of TTMessageController:
if (self.toWebMsgController == nil) {
self.toWebMsgController = [[PostToWebMessageController alloc] init];
}
UINavigationController *navController = [[UINavigationController alloc] init];
[navController pushViewController:self.toWebMsgController animated:NO];
[self presentModalViewController:navController animated:YES];
What happens though is this: The screen goes black ... the keyboard scrolls up into view ... and THEN the TTMessageController view shows up (not animated). When I dismiss the view via a Cancel button the screen goes black and then just disappears (no animation again).
Any ideas why this is happening? I've this with a number of other TT* controllers and I can't get one to animate right with showing modally.
Thanks
UPDATE:
This is happening in EVERY UIViewController that I try to present modally. Screen goes black, keyboard animates upwards and then view displays. Any ideas why this might be happening???
A day to figure this out ... hopefully someone will benefit from my pains!
Here is what is happening:
The UIViewController calling presentModalViewController is itself nested inside a UIScrollView that is contained in ANOTHER UIViewController. Apparently, cocoa touch doesn't much like this. Anyhow, to rectify the problem I did the following:
Add a property of type UIViewController to the UIViewController that will present a modal view controller (e.g. #property (nonatomic, retain) UIViewController *owningController;)
Set that property = to the topmost UIViewController (the one that contains the UIScrollView in this case)
In the UIViewController that shows the modal view ... change this
[self presentModalViewController:controller animated:YES];
to this ...
[owningController presentModalViewController:controller animated:YES];
I'm not sure why you are using a UINavigationController. If it is because you would like your toWebMsgController controller to have a nav bar when it loads in the modal view, try the following alterations to your code:
if (self.toWebMsgController == nil) {
self.toWebMsgController = [[PostToWebMessageController alloc] init];
}
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:toWebMsgController];
//[navController pushViewController:self.toWebMsgController animated:NO];
[self presentModalViewController:navController animated:YES];
If you don't require a nav bar in your modal view, you probably don't need a UINavigationController at all.
I had same issue.
Check that you root controller (if you present controller over it) for presentationStyle DOES NOT set to UIModalPresentationCurrentContext

iPhone modal view inside another modal view?

My App uses a modal view when users add a new foo. The user selects a foo type using this modal view. Depending on what type is selected, the user needs to be asked for more information.
I'd like to use another modal view to ask for this extra information. I've tried to create the new modal view like the first one (which works great) and it leads to stack overflow/“Loading Stack Frames” error in Xcode.
Am I going about this in completely the wrong way i.e. is this just a really bad idea? Should I rethink the UI itself?
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
Fixed. I got the behavior I wanted by pushing the second view controller to the first view controller's UINavigationController.
creation of 1st modal view
FooAddController *addController = [FooAddController alloc]
initWithNibName:#"FooAddController" bundle:nil];
addController.delegate = self;
addController.foo = newFoo;
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
[addController release];
creation of 2nd modal view (in FooAddController)
FooAddSizeViewController *addSizeController = [[FooAddSizeViewController alloc]
initWithNibName:#"FooAddSizeViewController" bundle:nil];
addSizeController.delegate = self;
addSizeController.foo = self.foo;
[self.navigationController pushViewController:addSizeController animated:YES];
[addSizeController release];
You need to take care on which instance you invoke the presentModalViewController when you deal with several levels of modal controllers.
Let's suppose you have :
[myControllerA presentModalViewController:myControllerB animated:YES];
Next time you want to display a modal controller while B has the focus, you should invoke
[myControllerB presentModalViewController:myControllerC animated:YES];
in order to get the parent controller properly set.
The hierarchy of controllers is then A-> B -> C
Did you try calling presentModalViewController on self.navigationControllerin both steps?