4

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?

Alessandro
  • 4,000
  • 12
  • 63
  • 131

3 Answers3

4

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.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
4

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.

Community
  • 1
  • 1
kjoelbro
  • 6,296
  • 4
  • 21
  • 18
2

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];    
arunjos007
  • 4,105
  • 1
  • 28
  • 43