Presenting UIViewController with clear background - ios

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!

Related

UIPopoverPresentationController can't setup arrow color

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

Present UIViewController as UIModalPresentationFormSheet & UIModalPresentationOverCurrentContext

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;
}

UI gets distorted when dismissing modal view controller in iOS 8

modalViewController = [storyboard instantiateViewControllerWithIdentifier:#"transparentFullViewController"];
listViewController.view.frame = CGRectMake(0, 0, 900, 333);
CGPoint center=modalViewController.view.center;
listViewController.view.center=center;
[modalViewController addChildViewController:listViewController];
[modalViewController.view addSubview:listViewController.view];
listViewController.view.center = [UIApplication sharedApplication].keyWindow.rootViewController.view.center;
this is how i present the modal view controller
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:modalViewController animated:NO completion:nil];
and this is how it is dismissed
[modalViewController dismissViewControllerAnimated:NO completion:nil];
when I dismiss the modalViewController in iOS 7, it works fine and return to the 2nd screen shot
but when I dismiss it in iOS 8.0, then the view becomes distorted as shown in 1st screen shot
Any help is appreciated.
Thank You.
In iOS 8 try to use another presentation style:
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
you are doing wrong,
you wrote
self.modalPresentationStyle = UIModalPresentationOverFullScreen;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
but it should be like
modalViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
modalViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

Moving between view by presentViewController. Whats going wrong?

Every time that I press the button activating the action above, my screen goes black.
I just want pass to another view (or same) without using the model proposed by storyboard.
What's wrong?
Thanks
- (IBAction)goToView:(id)sender {
ViewController *controller = [[ViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:controller animated:YES completion:nil];
You haven't configured your controller's view.
For example try this just before you presentViewController...
controller.view.backgroundColor = [UIColor orangeColor];
Your screen will turn orange...
Full example:
- (IBAction)goToView:(id)sender {
ViewController *controller = [[ViewController alloc]
initWithNibName:nil bundle:nil];
controller.view.backgroundColor = [UIColor orangeColor];
[self presentViewController:controller animated:YES completion:nil];
}

modalPresentationStyle not working in modal view in iOS5

I want to display a popup window in iPad using the UIView's presentModalViewController method in iOS5.
Even though I set the modalPresentationStyle to UIModalPresentationFormSheet, it only displays as full frame size.
I used the same code in iOS4 before, and it can display as a popup window. How to fix it in iOS5?
DetailViewController *d = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
self.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:d animated:YES];
Thanks.
Have you try
d.modalPresentationStyle = UIModalPresentationFormSheet;
instead of
self.modalPresentationStyle = UIModalPresentationFormSheet;
In iOS5, the modal view should be used as below.
DetailViewController *d = [[DetailViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:d];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:navigationController animated:YES];

Resources