I have this:
And have this, when presenting modally:
Some code jsut before presenting webview:
webViewController.modalInPopover = YES;
webViewController.modalPresentationStyle = UIModalTransitionStyleCoverVertical;
And have this in webViewController's viewDidLoad template:
self.contentSizeForViewInPopover = CGSizeMake(320.0, 436.0);
I've looked for every frame of every role playing view, but frame.sizes are correct.
Anybody with similar experience with a solution for that?
First I assigned a transistion style to presentation style.
And that was the enum for fullscreen.
Having this in webViewController init...
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
...solved the problem.
I'll try to move it to -(void)awakeFromNib; to get rid of hardcoded size.
Related
There are many q/a's on this topic, many of them referring to older versions of iOS. The best answer I could find on the subject was this one.
It almost works for me, but when presenting this over a UITabBarViewController subclass, it only partially works: I get a nice, semi-transparent view during the presentation animation, but once the presentation animation completes, the presented VC becomes opaque again.
Coded in Objective-C, but I'm happy to read Swift answers...
- (void)showBusyWithCompletion:(void (^)(BOOL))completion {
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5];
vc.view.opaque = NO;
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:^{
[self performSelector:#selector(hideBusy:) withObject:vc afterDelay:4];
}];
}
- (void)hideBusy:(UIViewController *)vc {
[self dismissViewControllerAnimated:vc completion:nil];
}
Again, the presenting VC is a UITabBarVC subclass, with nothing done to it except some code to record which tabs were visited. The presented vc is a vanilla view controller. Its view appears transparent red as it slides over, then turns opaque red (darker, like it's being blended with black) once the transition is complete.
How can I keep the background transparent after it appears?
It turns out that the answer I refer to above is correct, and I transcribed the setting improperly. To recap: this doesn't work (and the other answer didn't claim it did):
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
...but either of these do:
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
or as #TylerTheCompiler points out:
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
I'm trying to make a modal popup appear when scanning QR codes.
I have a .xib file that has the necessary views and is linked to my custom view controller. The usual stuff, except that I have a navigation controller so that I can add a close button at the top later and/or in case I need to push another screen.
To make things a little more complicated, I do not have direct access to the view controller (code is in a manager file). This is the code to create and launch the popup:
self.m_scannerVC = [[BarcodeScannerVC alloc] initWithNibName:NSStringFromClass([BarcodeScannerVC class]) bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.m_scannerVC];
// Set the navigation controller to be a modal popup.
navigationController.modalTransitionStyle = UIModalPresentationFormSheet;
// Set the size of the popup here.
navigationController.preferredContentSize = CGSizeMake(100, 200);
UIWindow *win = [[UIApplication sharedApplication].delegate window];
UINavigationController * winNav = (UINavigationController *)win.rootViewController;
winNav.providesPresentationContextTransitionStyle = YES;
winNav.definesPresentationContext = YES;
winNav.topViewController.providesPresentationContextTransitionStyle = YES;
winNav.topViewController.definesPresentationContext = YES;
winNav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
winNav.topViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
// And now present the view in a modal fashion.
[winNav.topViewController presentViewController:navigationController animated:YES completion:^{
// Once presented, set the capture layer to fix inside our camera preview box.
[self.captureLayer setFrame:self.m_scannerVC.m_viewCameraPreview.layer.bounds];
// Adding the camera AVCaptureVideoPreviewLayer to our view's layer.
[self.m_scannerVC.m_viewCameraPreview.layer addSublayer:self.captureLayer];
// Start the camera capture session as soon as the view appears completely.
[self.captureSession startRunning];
}];
Any tips on what I am doing wrong will be greatly appreciated!
I found out why, I'm so stupid!
navigationController.modalTransitionStyle = UIModalPresentationFormSheet;
should be
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
I'm developing for iPad and I have the following problem:
I'm trying to show a modal with his own size and his own UINavigationController, I already done that, but when I present the modal with his UINavigationController, I get this:
I want the UINavigationController to fit to modal size. I leave the code of how I'm presenting the modal:
- (void)createANewEvent:(id)sender
{
AddEditEventViewController *addEditEventViewController = [[(ScheduleViewController *)self.viewContainer storyboard] instantiateViewControllerWithIdentifier:#"AddEditEventViewControllerID"];
addEditEventViewController.modalPresentationStyle = UIModalPresentationFormSheet;
addEditEventViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addEditEventViewController];
[self.viewContainer presentViewController:navigationController animated:YES completion:nil];
}
How I resize the modal:
AddEditEventViewController.m
// Resize the view
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.view.superview.bounds = CGRectMake(0, 0, 548, 768);
self.view.superview.backgroundColor = [UIColor clearColor];
}
Hope you can help me!
Thanks in advance! :)
A view should never modify its superview's size or position.
The problem is that you're setting modalPresentationStyle on the root view controller instead of the view controller you're presenting, navigationController.
Delete:
addEditEventViewController.modalPresentationStyle = UIModalPresentationFormSheet;
addEditEventViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Delete the viewWillLayoutSubviews method you posted.
Add:
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
I would sub-class UINavigationController and implement the method:
preferredContentSize
Something like
- (CGSize) perferredContentSize {
return CGSizeMake(548,768);
}
That's all you should need to do to have properly resized modal views.
and have it return a CGSize structure with the size that you want the modal to be. This is the 'correct' way to do it per Apple documentation.
In conjunction, remove the viewWillLayoutSubviews method, that's just going to cause problems sometime in the future.
After [self.viewContainer presentViewController....] add:
navigationController.view.superview.bounds = CGRectMake(0, 0, 548, 768);
and get rid of your viewWillLayoutSubviews
I am creating a viewcontroller in this way:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"PhotoViewControlleriPhone" bundle:nil];
UIViewController *vc = [sb instantiateInitialViewController];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:vc animated:NO];
vc.view.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y + 64, imageView.frame.size.width, 200.000000);
vc.view.layer.cornerRadius = 10; // this value vary as per your desire
vc.view.clipsToBounds = YES;
The viewcontroller is not full screen, so you can still see the previous one. I want to be able to see it, but lock it. Just like when you use ios facebook sharing, you see the background, but it becomes darker and you can't interact with it. How can I do this?
I believe the problem is that you’re displaying it using -presentModalViewController:animated:. Using that method carries with it some assumptions about the view controller you’re hosting; one of the assumptions it makes (on iPhone-type devices, at least) is that the view controller takes up the entire screen and is opaque.
To get around this, try adding the modal view controller’s view to the current view controller’s view manually. You’ll need to set the view controller hierarchy up to match the view hierarchy, so your code would look like this:
[self addChildViewController:vc];
[self.view addSubview:vc.view];
You’ll need to adjust the incoming view’s frame to position it within its new superview, but that should allow you more freedom.
My workaround is to take a screenshot with code, pass the UIImage as a parameter to the new UIViewController, and display it as a background image. In that way it appears transparent, and the you don't have to disable the underlying controls that might be reachable/accessible.
iOS8+
You can use below code snippet for iOS8+, its worked for me
SecondViewController *secondViewController = [[SecondViewController alloc] init];
secondViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:secondViewController animated:YES completion:nil];
So I have a popover with a button in it. When that button is pushed, I want the popover to go away. It seems easy enough, but I can't figure it out for the life of me. The code I use to show the popover is below:
AddCategoryViewController* content = [[AddCategoryViewController alloc] init];
UIPopoverController* aPopover = [[UIPopoverController alloc]
initWithContentViewController:content];
aPopover.delegate = self;
[content release];
// Store the popover in a custom property for later use.
self.addCategoryPopover = aPopover;
[aPopover release];
[addCategoryPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Within the addcategoryviewcontroller, I have:
-(IBAction)saveAddCategory:(id)sender {
if (rootViewController == nil)
rootViewController = [[RootViewController alloc] init];
[rootViewController.addCategoryPopover dismissPopoverAnimated:YES];
[rootViewController dismissPopover];
}
Rootviewcontroller is where the popover is being created from. Unfortunately, neither of those methods work to dismiss it. any help?
You would be seeing a warning at this line.
aPopover.delegate = self;
and if you would execute your code. The app would crash. Instead you need to do it like this.
I have
- (void)viewWillDisappear:(BOOL)anAnimated
{
[self.dPopover dismissPopoverAnimated: NO];
self.dPopover = nil;
[super viewWillDisappear: anAnimated];
}
and don't see why this wouldn't work in your case.
Your if is a bit troubling, so my guess is you aren't talking to the view you think you are. rootViewController.addCategoryPopover is probably nil, because you made a new controller.
I think I answered just a similar question with the solution I used to dismiss a popover with a UIView loaded from a MKMapView.
The use of my solution is basically the same as for any other view loading a popover.
Have a look at:
How to dismissPopoverAnimated on iPad with UIPopoverController in MKMapView (SDK3.2). I hope that solved your problem.
use NSNotificationCenter To DissmissPoperController Fro Father viewControll