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.
Related
I have a view that is presenting another view via
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[weakSelf presentViewController:navigationController animated:YES completion:^{}];
The only problem is that the "main" view that presented that new view, has buttons that can be touched because the ModalPresentationFormSheet doesn't take the full screen. I would like to keep that format, but prevent clicks while the Modal is being presented. I know I could do this this check on every possible buttons, but I am sure there is another way!
if (![weakSelf presentedViewController])
Thanks!
You can put the "new view" as a child view of another view that has full screen and make that "parent view" background color to clear color so you can see the "main view" also. Now you can't click the button cause you are actually clicking the view that is the parent on "new view"
One approach could be to place an invisible 'shield' above the hosting view controller, but below the form sheet.
Basically, create an empty UIView whose background color is clear. Add that as a subview to your presenting view controller just before you make your call:
[weakSelf presentViewController:navigationController animated:YES completion:^{}];
Now, this doesn't necessarily mean such a solution is in good taste. That is, the form sheet style isn't meant to be exclusive in that way, and it can be confusing if the UIView installed above is clear. So, you could reduce the alpha value on that view to turn it into a dimming screen, to help the user understand that the form sheet is the only thing they can interact with at that time:
UIView *dimmingScreen = [[UIView alloc] initWithFrame:self.view.bounds];
dimmingScreen.alpha = 0.5; // play with this value to get different degrees of dimming
dimmingScreen.backgroundColor = [UIColor blackColor]; // play with different colors
[self.view addSubview:dimmingScreen];
// Now present your form sheet, as you were:
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[weakSelf presentViewController:navigationController animated:YES completion:^{}];
You'll want to be able to remove the dimming screen too, so best make it a view controller property you can access so as to remove when needed.
I am looking for a way to implement this kind of popover.
Are there basic iOS commands to generate this style instead of the usual Arrow + Border popover that we see in XCode? Or is there an API to do this kind of thing.
The popover is coming up from the bottom of the screen, just like in the App Store animation sometimes.
Thank you
What you want to do is create a custom UIVIewController with the modal presentation style set to UIModalPresentationFormSheet:
YourCustomViewController *customVC = [[YourCustomViewController alloc] initWithNib:#"YourCustomViewController" bundle:nil];
customVC.modalPresentationStyle = UIModalPresentationFormSheet;
[self self presentViewController:customVC animated:YES completion:nil];
You will also have to create a toolbar and format it correctly with a "close" or "done" button that will dismiss the view controller
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
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.
This question already has answers here:
Transparent Background with a Modal UIViewController
(6 answers)
Closed 9 years ago.
I have a two UIViewControllers, and I am displaying the secondViewController modally over the firstViewController. My secondViewController contains a subview which is UIView with some buttons. Now what I want to do is, make the SecondViewController semi transparent so that my firstViewController is visible and only show the subview modally which is not transparent.
Reagards
Ranjit
when you present your view controller, view of previous controller is removed so if you set any alpha for your current controller's view, you will get UIWindow's background.
if you intend to play with the transparency, then instead of doing presentModalViewController, in first viewcontroller, [self.view addSubView:controller2.view];
and make controller2.view.alpha = 0.5;//whatever transparency level u want
If you're targeting iOS 5.0 and above, you can use the container view controller approach:
// create the modal view controller
MyModalController *modal = [[MyModalController alloc]
initWithNibName:#"MyModal" bundle:nil];
[modal willMoveToParentViewController:self];
// add it to the controllers and views hierarchies
[self addChildViewController:modal];
modal.view.frame = self.view.bounds;
[self.view addSubview:modal.view];
[modal didMoveToParentViewController:self];
Then whatever alpha you set for the main view's background in IB or in code will be respected.