Rotate view below modal view - ios

I have an UIViewController(called MainViewController) which presents modally a semi-transparent view (HelpOverlayViewController):
HelpOverlayViewController *helpOverlayViewController = [[HelpOverlayViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
helpOverlayViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:helpOverlayViewController animated:YES completion:nil];
If the user rotates the device while the HelpOverlayViewController is shown it only rotates HelpOverlayViewController and not the MainViewController i.e. the parent controller. This is a problem since HelpOverlayViewController is semi-transparent and MainViewController is visible below it.
Both controllers have the method
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
They both rotate fine independently.
Is there some way I can force the underlaying view controller to rotate when the modal view does?

I do know that issues like this will likely be largely resolved with iOS 6 as it has a different model for handling rotations.
However, that doesn't help you now. You might be best off just making your HelpOverlay a UIView and not a UIViewController. You can add this semi-transparent view onto the top of your MainViewController (or any other). You can still create an animation (like a fade-in) when adding this subview to your view hierarchy. With this model, you'll no longer have any issues with rotations.

Related

iOS: Apply view rotation to view controller under modal view

I have been following a solution on this question in order to display a view with a transparent background. The issue that I'm having is once the modal view controller has been displayed, the underlying view doesn't get rotated anymore.
For example if A is my view controller, then B is my modal view. The issue is as follows. I currently have my device in portrait and have A displayed. I then present B modally. I then rotate my device and B rotates with it, however A stays as it was.
Please could someone advise on how to handle this rotation so that the underlying view (A) gets rotated too?
ModalViewController is used to interrupt the current workflow and displaying a new set of views. So when you present modally, here in this case you are presenting B, the current active Viewcontroller is B and not A.
A ViewController is traditional controller objects in the Model-View-Controller (MVC) design pattern. They also take care of user interface, gesture recognitions,event management(of buttons for example) and the alignment of views in present in them.
When you presented B, the current viewcontroller changed from A to B and hence when you try to rotate(if the orientation support is provided) the view of B is effected as its the viewcontroller active and it responds to the rotation. Normally we go unnoticed these because the view is opaque. Here in your case the view is transparent and we notice that A has not responded to rotation.
I tried the above example in iOS6 (from the one you mentioned)
ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
here A remained in portrait mode
When i did this adding the second viewcontroller's view as a subview, A changed to landscape
ViewController2 *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"VC2"];
vc.view.backgroundColor = [UIColor clearColor];
self.view addSubview:vc.view];
this happend because in the second trial the active viewcontroller was A and not B as B's view was a subview added to A. Go through Apples's Document on
About ViewController
About windows and views
Presenting ViewControllers

popover content view doesn't display while viewcontroller has a child VC present

I have a container view controller that consists of a navigation view at top, and a content view for the remainder of the screen. The navigation menu consists of several buttons, some of which present a popover with UITableView for secondary navigation. This all worked until I assigned a child view controller and set it's view as subview of the content view. Now, the popover appears, but has nothing inside it (no tableview, just black).
Why is this?
Here's the code I added for the child vc in container view:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
ContentWebViewController *initialVC = [[ContentWebViewController alloc] init];
[self addChildViewController:initialVC];
initialVC.view.frame = self.view.bounds;
[self.containerView addSubview:initialVC.view];
self.currentController = initial;
}
See the screenshot below. I added a vc with a simple webview showing google (just as a placeholder for now). The popover was working fine before I assigned the child VC.
Maybe it will help other in other cases -
If you are using size classes (probably you are since you are developing this to iPad) -
Design your popover view controller in Any-Any size and it should be OK - after that you can return to your wanted size.
(You can also uninstall the size classes of any object in that view controller instead of redesign the VC)
I somehow (don't ask me how) changed the class that my table view controller was inheriting from. It should have been (obviously) UITableViewController, but was UITableViewController, so initWithStyle was not being called....

Programmably show UIViewController with transparent background [duplicate]

This question already has answers here:
Transparent Background with a Modal UIViewController
(6 answers)
Closed 9 years ago.
I am trying to display on the iPad a UIcontroller in my original viewcontorller, but smaller sized, so that the user is able to interact with it as well as with the contorller in the background. this was my aim but it is ok even if the user can't interact with the controller on the background, but it is essential to see the contorller in the background. I tried this code:
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
controller.view.layer.cornerRadius = 10; // this value vary as per your desire
controller.view.clipsToBounds = YES;
controller.view.frame = CGRectMake(343, 163, 316, 546.5);
This displays the controller with the set frame, but in the background you can't see the other controller, but just black. Why?
Definetely use this Presenting View Controllers from Other View Controllers and this About View Controllers
The section "Presentation Styles for Modal Views" says about your problem I think.
There are different presentation styles for controllers. You can set property - modalPresentationStyle to UIModalPresentationPageSheet or UIModalPresentationFormSheet that shows view controllers above other.
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
controller.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:controller animated:YES];
Another way is using UIPopoverController. It designed for showing views that sized not all the screen view. But the touches on other view controller will hide it.

With UIPresentationFormSheet, why doesn't my view move above the keyboard when it is up?

Apple says:
UIModalPresentationFormSheet
The width and height of the presented view are smaller than those of the screen and the view is centered on the screen. If the device is in a landscape orientation and the keyboard is visible, the position of the view is adjusted upward so that the view remains visible. All uncovered areas are dimmed to prevent the user from interacting with them.
But my view doesn't move up when the keyboard is visible. I basically want to present a textview modally above the keyboard so the user can enter text and then hit send (in a nav bar button on the presented view.)
My presenting view is a UISplitViewController (not one of its children) and I'm presenting UINavigationController who's top view controller is basically a UITextView. Rotation works, but the presented view is overlapped by the keyboard in both orientations.
I found some questions asking how to resize the presented view in this case, which is nice, but I don't want to have to make assumptions by resizing manually in the presenter or in the presented view. It seems like it should just pick a decent (undocumented) size just move it up automatically when the keyboard shows.
My presenting code looks like this:
MyViewController *vc = [[MyViewController alloc] init];
UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:vc] autorelease];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self.splitViewController presentModalViewController:nav animated:YES];
As I was finishing up my question, I realized I was calling becomeFirstResponder on my UITextView in viewWillAppear. If you change it to viewDidAppear it will work, which makes sense.

Display Modal View Controller over detail view in UISplitViewController

I have a UISplitViewController in an iPad app. When something is selected from the table I want to fade in a modal view controller over the detail view. I can present it without a problem, but for some reason I can't get it to match the frame of the detail view. I would like it to stick to the detail view controller frame on rotation as well. Does anyone have any experience with this? This is my code to display. The detail view controller reference is set in the app delegate and passed down the table controllers.
QuestionViewController_iPad *questionView = [[[QuestionViewController_iPad alloc] initWithNibName:#"QuestionViewController_iPad" bundle:nil] autorelease];
questionView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Not quite
questionView.modalPresentationStyle = UIModalPresentationCurrentContext;
questionView.questionQuizCon = [QuestionQuizConnection firstQuestionForQuiz:quizCatCon.quiz];
// Maybe something like this?
[self.detailViewController presentModalViewController:questionView animated:YES];
When the modal view presents, it matches the size of the detail view controller, but it doesn't but it sits on the top left of the screen behind the master view controller. It also doesn't resize on rotation. I have the springs and struts set to auto size and fill. The height changes on rotation but it won't fill the width.
I couldn't get this to look right any way I tried it so I ended up just using view transitions to make it look like pages being torn off a notebook. That looks better anyway.
// Transition the view on as a subview.
[UIView transitionWithView:self.detailViewController.pageView duration:1.0
options:UIViewAnimationOptionTransitionCurlUp
animations:^ {
questionView.view.frame = CGRectMake(0, 0, self.detailViewController.pageView.frame.size.width, self.detailViewController.pageView.frame.size.height);
[self.detailViewController.pageView addSubview:questionView.view];
// Watch this one
self.detailViewController.currentQuestionViewController = questionView;
}
completion:nil];
After [self.detailViewController presentModalViewController:questionView animated:YES]; you should set center property and/or frame of questionView. Be sure that you set it after presenting modal view.

Resources