UI gets distorted when dismissing modal view controller in iOS 8 - ios

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;

Related

presentViewController(UIViewController) not working

I wanted to populate my uncontrolled view as presentViewController on my app, but it does not work. I do not want to cover the entire screen. Like on the iPad, it should view at the centre and frame, which is preferred.
Below is my code which covers the entire screen:
MyView *testview = [[MyView alloc]init];
testview.modalPresentationStyle = UIModalPresentationFormSheet;
testview.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController: testview animated:YES completion:nil];
I do not want to push my UIViewController...
You cannot present a View. You must present a controller. for example:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
MyViewController* vc = [mainStoryboard instantiateViewControllerWithIdentifier:#"MY_CTL_ID"];
[self presentViewController:vc animated:NO completion:nil];
Here's what worked for me (iOS 9 or later):
MyViewController *testVC = [[MyViewController alloc] init];
testVC.modalPresentationStyle = UIModalPresentationFormSheet;
testVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Both of these are necessary to make it present as a form sheet on an iPhone/iPod.
testVC.presentationController.delegate = vc;
testVC.presentationController.overrideTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:#[[UITraitCollection traitCollectionWithUserInterfaceIdiom:UIUserInterfaceIdiomPad]]];
// Set the size if you don't set it elsewhere.
testVC.preferredContentSize = CGSizeMake(270, 130);
[self presentViewController:vc animated:YES completion:nil];
Also, the view controller you are presenting needs implement the UIAdaptivePresentationControllerDelegate protocol:
#interface MyViewController () <UIAdaptivePresentationControllerDelegate>
...
#end
#implementation MyViewController
...
(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection {
// This makes it use the presentation style that was set when it was presented.
return UIModalPresentationNone;
}
...
#end

Presenting UIViewController with clear background

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!

In iOS 7, using UIModalPresentationCurrentContext for an animated modal presentation doesn't animate

In iOS 8, when presenting a modal (lets say with a transparent background), we need to set the segue (or the modal) to use the presentation style of UIModalPresentationOverCurrentContext. This is working as expected.
To accomplish the same thing for iOS 7, you instead, need to set the presenting view controller to have a modal presentation style of UIModalPresentationCurrentContext. Here's where I'm having an issue. I present the modal with animation, but it doesn't animate. After it is presented, everything works fine, even animating the dismissal. Further, if I change the presentation style to UIModalPresentationFullScreen, it animates correctly.
I've searched around and read other posts, but I can't find the cause of this or a solution.
ViewController *vcObj = [[ViewController alloc] initWithNibName:NSStringFromClass([ViewController class]) bundle:nil];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vcObj];
if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
navCon.providesPresentationContextTransitionStyle = YES;
navCon.definesPresentationContext = YES;
navCon.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:navCon animated:NO completion:nil];
}
else {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[self presentViewController:navCon animated:NO completion:^{
[navCon dismissViewControllerAnimated:NO completion:^{
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:navCon animated:NO completion:nil];
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;
}];
}];
}

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