0

Possible Duplicate:
Transparent Modal View on Navigation Controller

I want to make my viewController with transparent backgroundColor but i don't have any luck..

I've tried to set/use...

  • self.view.backgroundColor = [UIColor clearColor]; - still I have white colored background.
  • self.view.alpha = .0f; - all my thing in my VC are missing but i still have white background
  • self.view.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:.7f] and still white background below my transparent view.

EDIT1:

Tested on:

  • iPad3, iOS 6.0
  • iPad 6.0 Simulator
Community
  • 1
  • 1
h4cky
  • 899
  • 1
  • 13
  • 33

5 Answers5

2

After little more researching I've found this approach:

Original code:

MyViewController *popUpViewController = [[MyViewController alloc] init];
[self presentModalViewController:popUpViewController animated:YES];
[popUpViewController release];

Modified code:

TTPopUpViewController *popUpViewController = [[TTPopUpViewController alloc] init];
popUpViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:popUpViewController animated:YES];
[popUpViewController release];

So as you can see i've using modalPresentationStyle property on my ViewController which I wan't to present, right before call presentModalViewController:animated:

NOTE: My ViewController view have size of {680, 700}

It present my ViewController view with size of {540, 620} and because my original size bigger I have parts my borders and shadows hidden but with little modification of my view look and feel it will be okay.

However this approach seems to give me what I want.

========

For more information please refer to following Apple documentation:

UIViewController Class Reference

h4cky
  • 899
  • 1
  • 13
  • 33
1

Generally not possible using presentModalViewController. Here's a similar question with a workaround:

Transparent Modal View on Navigation Controller

Community
  • 1
  • 1
TomSwift
  • 39,369
  • 12
  • 121
  • 149
1

The problem with what you are doing is that the ViewController's view below the transparent one is removed from the screen after presenting the new ViewController. Manually adding a new view on top of the current ViewController and setting that to transparent will work though.

brynbodayle
  • 6,546
  • 2
  • 33
  • 49
0

You can't use presentViewController to achieve this, however there's a way - which is not very elegant.

.h file
@propert(strong,nonatomic) MyCustomViewController *myCustomVC;

.m file
-(void) presentTransparentViewController
{
if(self.myCustomVC==nil) {
    _myCustomVC = [[MyCustomViewController alloc] init];
    }

self.myCustomVC.view.backgroundColor = [UIColor clearColor];
UIView *view = self.myCustomVC.view;
view.opaque = NO;

view.frame = self.view.frame; //assuming the views are the same size
[self.view addSubview:view];
}

You can also add the view below the main screens frame and present it with an animation.

Kaan Dedeoglu
  • 14,765
  • 5
  • 40
  • 41
0

I just found a workaround for that. Just create a 1X1 of UIViewController and add it to your parent view controller. And show the modal view controller in that UIViewController.

on viewDidLoad;

self.dummyViewController = [[UIViewController alloc] init];
 [self.dummyViewController.view setFrame:CGRectMake(0, 0, 1, 1)];
 [self.view addSubView:self.dummyViewController.view];

when you need to open a transparentViewController;

[self.dummyViewController presentModalViewController:yourTransparentModalViewController animated:true];
Agent Chocks.
  • 1,312
  • 8
  • 19
Ali Ersöz
  • 15,860
  • 11
  • 50
  • 64