Presentmodalviewcontroller causes mkmapview to disappear - iphone

Hitting my head against a wall here. Feel like this should be simple, but just can't figure it out.
I have a Window with a UIViewController set as its rootviewcontroller. In the rootviewcontroller, I have a full screen mkmapview. Catch is, when presentmodalviewcontroller gets called, I see my mkmapview completely disappear (the color of my viewcontroller's view underneath instantly comes up) just as the new screen comes flying in. Once I dismissModalViewControllerAnimated, it goes back to a (black) screen.
I've tested this a bit by removing the iboutlet of the mapview in IB - then the transitions work like a charm.
I don't think it's this code as I'm using the template Utility app as a guide - but just to give some substance:
-(IBAction)settingsGearPressed:(id)sender
{
SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:#"SettingsViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
}

Basically I was removing the mapview in ViewWillDissapear

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.

Form Sheet Modal View Animations

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;

iPad/iOS modalView jumps left on dismiss

I added a modalView to my App, everything working fine, but on closing the modal, the whole modalView jumps about 1-2 centimeters to left while it disappears.
I did not find any reason for it yet, so here is the code regarding modal:
AppController:
- (void) showNameModal:(Player *)player
{
namesModal = [[PlayerModalView alloc] init];
namesModal.delegate = self;
namesModal.player = player;
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:namesModal];
navCon.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navCon animated:YES];
[navCon release];
[namesModal release];
}
- (void)didDismissModalView
{
[self dismissModalViewControllerAnimated:YES];
}
ModalView:
- (void)dismissView:(id)sender
{
[delegate didDismissModalView];
}
called via navigation buttons as well ass via keyboard by
[self dismissView:nil];
As you can see, there is nothing special in it, could be taken from a manual actually.
What happens in detail:
Modal appears in center of screen, slides in from the bottom. centered all time.
i can handle some actions in the modalView, it stays centered.
now, dismissing the view makes it jumping to the left, than slides out.
Since it's a forced landscape-right app (currently), I was only able to notify the left-jump.
Any ideas how to get this jumping away?
Thanks
Try this,
- (void)didmissView:(id)sender
{
[self.navigationController didmissModelViewControllerAnimated:YES];
}
You are not modally presenting an instance of PlayerModalView but rather a UINavigationController. The left jerk you see is most likely the default animation of the navigation controller attempting a slide transform to the (non-existant) previous view.
It doesn't sound like you need a navigation controller for the PlayerModalView. Instead, you should create an ordinary view controller for it.
This solution seems to work well: Modal View Controller with keyboard on landscape iPad changes location when dismissed
To simplify resigning the first responder (if finding it is difficult), you can just call
[self.view endEditing:YES];
[self dismissModalViewControllerAnimated:YES];
The problem is that the UIViewController you're showing modally doesn't allow the orientation you're presenting it in, so when it disappears, it will do that in a direction that it considers "allowed".
Add this to the UIViewController for you modal view:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}

Help! Adding image to UIViewController Transition! :S

I currently have several view controllers and transitions set up throughout my app using:
ViewController2 *controller2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
controller2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller2 animated:YES];
[controller2 release]; controller2 = nil;
What I really want is when the vertical transition is made, I want an image of bubbles to travel up the screen with the transition. Is there anyway of adding an Image to these transitions. If not I would like to know how to create this effect as I have seen it in apps before.
Thanks in Advance,
Adam
Simple way would be to add a UIImageView the size of the view being animated, with your bubbles image set to it as a subview of that view. You can then remove it in the viewDidUnload or where appropriate in your code.

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