How do I present a UITableViewController with a blurred background as a form sheet over the current context?
- (void)viewDidLoad {
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
}
It works fine full screen, on iPhones set with UIModalPresentationOverCurrentContext
But for iPad if I want to display it as a form sheet then I need to set modalPresentationStyle to UIModalPresentationFormSheet.
How do I set both?
I found I needed to use UIModalPresentationPopoverfor the modalPresentationStyle and then you can set the view controllers popoverPresentationColor to clearColor.
FAGalleryTableViewController *vc = (FAGalleryTableViewController *)[segue destinationViewController];
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
vc.modalPresentationStyle = UIModalPresentationPopover;
vc.popoverPresentationController.sourceView = _storeButton;
vc.popoverPresentationController.backgroundColor = [UIColor clearColor];
vc.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionDown;
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
After searching so much, this worked for me on iOS10+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
//IPAD
CamVC *destination = segue.destinationViewController;
[destination setModalPresentationStyle:UIModalPresentationFullScreen];
[destination setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
}else{
// IPHONE
CamVC *destination = segue.destinationViewController;
destination.modalPresentationStyle = UIModalTransitionStyleCrossDissolve;
destination.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}
Related
The popover's preferred size is only works if the height is greater than 320.
I have searched a lot to solve this issue. But didn't find any answer. Is there any minimum size that the popover should satisfy in iPad? If not, what i'm missing?
Code:
UIViewController *viewController = [subStoryboard instantiateViewControllerWithIdentifier:SMFormViewControllerSBID];
controller = [[UINavigationController alloc] initWithRootViewController:viewController];
SMFormViewController *formViewController = (SMFormViewController *)controller.topViewController;
formViewController.modalPresentationStyle = UIModalPresentationPopover;
formViewController.preferredContentSize = CGSizeMake(375, 320);
popController = [controller popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popController.delegate = self;
popController.sourceView = tblDocDetails;
NSInteger section = [tblDocDetails numberOfSections] - 1;
CGRect rectCustomLoc = [tblDocDetails rectForFooterInSection:section];
popController.sourceRect = CGRectMake(rectCustomLoc.origin.x, rectCustomLoc.origin.y, 130, rectCustomLoc.origin.y/2);
[self presentViewController:controller animated:YES completion:nil];
Note:
I tried, adaptivePresentationStyleForPresentationController: & adaptivePresentationStyleForPresentationController: to return UIModalPresentationNone.
I tried the following:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btnOpen = [UIButton buttonWithType:UIButtonTypeCustom];
[btnOpen setFrame:CGRectMake(100, 100, 100, 44)];
[btnOpen setTitle:#"POP" forState:UIControlStateNormal];
[btnOpen setBackgroundColor:[UIColor grayColor]];
[btnOpen addTarget:self action:#selector(btnOpen:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnOpen];
}
- (void)btnOpen:(id)sender {
UIView *sourceView = (UIButton *)sender;
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
vc.modalPresentationStyle = UIModalPresentationPopover;
vc.preferredContentSize = CGSizeMake(150, 150);
[self presentViewController:vc animated:YES completion:nil];
UIPopoverPresentationController *popVc = vc.popoverPresentationController;
popVc.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popVc.sourceView = sourceView;
popVc.sourceRect = sourceView.bounds;
}
and it resulted in this (iPad Air 2, iOS 11.2):
Here is a solution based on your example, I think your use of GCD to show the popover might be causing the issue...
UIViewController *viewController = [subStoryboard instantiateViewControllerWithIdentifier:SMFormViewControllerSBID];
controller = [[UINavigationController alloc] initWithRootViewController:viewController];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.preferredContentSize = CGSizeMake(375, 320);
[self presentViewController:controller animated:YES completion:nil];
popController = [controller popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popController.delegate = self;
popController.sourceView = tblDocDetails;
NSInteger section = [tblDocDetails numberOfSections] - 1;
CGRect rectCustomLoc = [tblDocDetails rectForFooterInSection:section];
popController.sourceRect = CGRectMake(rectCustomLoc.origin.x, rectCustomLoc.origin.y, 130, rectCustomLoc.origin.y/2);
My popover sometimes doesn't visible, because of the sourceRect was incorrect.
Since I embedded ViewController in a Navigation Controller, preferredContentSize should set to Navigation Controller.
controller.preferredContentSize = CGSizeMake(375, 100);
& in ViewController:
self.navigationController.preferredContentSize = contentsize;
And Changed sourceRect to:
CGRect rectCustomLoc = [table rectForFooterInSection:section];
rectCustomLoc.size.width = sender.frame.size.width;
popController.sourceRect = rectCustomLoc;
I am struggling to understand why the following views, one for CABTMIDILocalPeripheralViewController and the other for CABTMIDICentralViewController show different behaviour in my iOS app (written in Objective-C)
- (IBAction)configureCentral:(id)sender
{
CABTMIDICentralViewController *viewController = [CABTMIDICentralViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController]; // this will present a view controller as a popover in iPad and modal VC on iPhone
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(doneAction:)];
navController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popC = navController.popoverPresentationController;
popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popC.sourceRect = [sender frame];
viewController.preferredContentSize = CGSizeMake(320., 400.);
popC.backgroundColor = [UIColor darkGrayColor];
viewController.view.backgroundColor = [UIColor darkGrayColor];
UIButton *button = (UIButton *)sender;
popC.sourceView = button.superview;
[self presentViewController:navController animated:NO completion:nil];
}
Opens a popup view on an iOS device, which does not show any 'done' button to dismiss the view.
CABTMIDICentralViewController shows no button to close/dismiss the view
While on an iPad tapping outside the view will close it, on an iPhone the view takes the size of the screen and exiting/closing becomes impossible.
The same code used for the CABTMIDILocalPeripheralViewController works as expected.
- (IBAction)configureLocalPeripheral:(id)sender
{
CABTMIDILocalPeripheralViewController *vController = [[CABTMIDILocalPeripheralViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vController];
vController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(doneWithPeripheral:)];
navController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popC = navController.popoverPresentationController;
popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popC.sourceRect = [sender frame];
vController.preferredContentSize = CGSizeMake(320., 400.);
popC.backgroundColor = [UIColor grayColor];
vController.view.backgroundColor = [UIColor darkGrayColor];
UIButton *button = (UIButton *)sender;
popC.sourceView = button.superview;
[self presentViewController:navController animated:NO completion:nil];
}
CABTMIDILocalPeripheralViewController has a 'done' button
What is going wrong here? I have tested to make the views wider to see whether available space in the Navigation bar would have caused this.
Thanks.
I'm writing iOS FFI methods for Kony application. In that, I'm presenting a viewcontroller with clear backgroundcolor. But, it's showing a white background view. I'm not using storyboars, I'm designing views in code only. In the newviewcontroller viewdidload, I set the self.view background color to clearcolor.
Here's what I have tried,
NewViewController *newVC = [[NewViewController alloc]init];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];
I'm new to KonyUIContext, how can I fix this?
Can anyone help me on this?
Try this code... It works perfectly for me....
MyViewController *modalViewController = [[MyViewController alloc] init];
modalViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[KonyUIContext presentViewController:modalViewController animated:YES completion:nil];
try this , You just need to set backgroundcolor to clear color of your viewcontroller's view .
NewViewController *newVC = [[NewViewController alloc]init];
newVC.view.backgroundColor = [UIColor clearColor];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];
Hope this Helps!
I am trying to present popover with UIPopoverPresentationController class on the iPhone.
I need to present navigation controller inside the popover. So I do the following:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.preferredContentSize = size;
navigationController.modalPresentationStyle = UIModalPresentationPopover;
self.currentPopoverController = navigationController.popoverPresentationController;
self.currentPopoverController.backgroundColor = [UIColor commonApplicationBgColor];//My common app blue color
self.view.alpha = 0.7;
[self presentViewController:navigationController animated:YES completion:nil];
It is working, but arrow colour is differ from the popover navigation bar background colour. I checked they use the same [UIColor commonApplicationBgColor], but it looks like arrow colour is darker. Tried setup alpha for self.currentPopoverController.backgroundColor, but it is still has wrong color.
Please check image:
if you don't want arrow then you can pass 0 to permittedarrowdirection like,
[popoverController presentPopoverFromRect:YOUR_RECT
inView:self.view
permittedArrowDirections:0
animated:YES];
Update :
you can set like,
popover = [[UIPopoverController alloc] initWithContentViewController:contentViewController];
popover.backgroundColor = contentViewController.view.backgroundColor;
set bacground color to popovercontroller.
Update 2 :
myPopoverViewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:myPopoverViewController animated: YES completion: nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[myPopoverViewController popoverPresentationController];
presentationController.permittedArrowDirections =
UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight;
presentationController.sourceView = myView;
presentationController.sourceRect = sourceRect;
presentationController.backgroundColor = [UIColor grayColor]; //set your expacted color here.
Hope this will help
I have a UIViewController called MyViewController. When I click on a button, I go to another UITableVIewController.
The code I use to navigate to this TableviewController is :
UIStoryboard *s = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *v = [s instantiateViewControllerWithIdentifier:#"tbviewc"];
v.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:v animated:YES completion:NULL];
I have set the NavigationController to this TableViewController.
Now I want to set the title for it. How can I do this?
Nb: This is a storyboard application.
None of the following worked :
self.navigationItem.title = #"the title";
I guess your self.navigationController is nil
You should do this:
UIViewController *v = [s instantiateViewControllerWithIdentifier:#"tbviewc"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:s];
v.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:nav animated:YES completion:NULL];
Then try to use self.title = #"title"; in UIViewController(v)
Or not nil, try this:
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0,40,100)];
title.text = #"title";
UINavigationController *nav = [UINavigationController new];
nav.navigationItem.titleView = title;
try
v.title = #"the title"
v is your UIViewController object.