Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Modal view with semi-transparent background

TomWhitsonTomWhitson Posts: 40Registered Users
edited August 2011 in iPhone SDK Development
Hi all,

I want to pop up and animated modal view (with controller) over my current view. I have that working fine using a .xib file and some code like

[PHP]
ModalViewController *popupController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
[self presentModalViewController:popupController animated:YES];

[/PHP]

What I would like to do is for the modal view to have a semi-transparent background image so that the views underneath can still be seen. I have used a semi transparent image as a background but it doesn't work. Has any one experienced this? Or is there some standard code/way to do this.

Cheers,
Tom
Post edited by TomWhitson on
<a href="http://www.tomwhitson.co.uk/bombsaway" target="_blank">Bombs Away out now! (non iTunes link)</a><br />
<br />
<a href="http://www.tomwhitson.co.uk/starjumper/" target="_blank">StarJumper out now! (non iTunes link)</a>
· ·

Replies

  • toughturtletoughturtle Posts: 50Registered Users
    edited March 2009
    As far as I know it can't be done. Modals are solid and cover 320x480 only. Instead you can add a subview and animate with CAanimation.
    · ·
  • mrbelkmrbelk Posts: 34Registered Users
    edited March 2009
    Why can't you simply set the alpha value of the background of the modal view to something less than 1?

    I think another way is to use an opaque image and set the transparency of the whole view to something less than 1. The downside (and partial upside) to this is that any subviews on the modal view will take the same alpha value.

    Maybe you could set the alpha of the modal view's background to zero, making the background completely transparent, then overlay a partially transparent image, then whatever UI elements you want? I think that might work.

    -MrB
    · ·
  • spstanleyspstanley Posts: 10Registered Users
    edited May 2009
    I have this same problem. Not sure how to get around the fact that the background just isn't transparent. I got an off-the-cuff answer from someone at Apple that maybe they're throwing up an opaque window, but my experiments with that theory went nowhere....
    · ·
  • SteveYSteveY Posts: 191Registered Users
    edited July 2009
    So we're stuck with solid backgrounds on view controllers that are presented modally? Setting the background of the View to alpha=0 has no effect ,nor does this, in the view controllers viewDidLoad:
    self.view.backgroundColor = [UIColor clearColor];
    
    · ·
  • kryekrye Posts: 362Registered Users
    edited August 2009
    I'm having the same problem. Can't find a solution.

    I wanted to push a modal view onto the stack with semi-transparency and a clear background so that the text in my UIWeb view look like a heads up display. But no luck so far.
    <a href="http://ineedcoffeetocode.com" target="_blank">iNeedCoffeeToCode.com</a> <a href="http://rescuemyclassicmac.com" target="_blank">RescueMyClassicMac.com</a> <a href="http://ryemac3.net" target="_blank">RyeMAC3.net</a>
    · ·
  • coder19coder19 Posts: 57Registered Users
    edited August 2009
    I don't think it's possible unless Apple updates the modalViewController class.
    · ·
  • shomarimshomarim Posts: 3New Users
    edited October 2009
    It is possible but I don't know how. I'm trying to figure out how to do this. The USAToday app does this with their survey. The modalview comes up, covers the tabbar and everything. The top bar is still visible through the modalview.
    · ·
  • coder19coder19 Posts: 57Registered Users
    edited October 2009
    I haven't seen the App you are referencing, but is it possible that it's just a regular view that they're popping up and not necessarily invoking a modal view controller?
    · ·
  • yoichiyoichi Posts: 5New Users
    edited February 2010
    Apparently the reason is that the modal view removes (replaces) the previous view from the window. So, even if the modal view itself is semi-transparent, there is nothing to show underneath. That is the problem. Apparently this was proven.

    So people are suggesting to make a "modal" view to be inserted as the top view, or draw the "modal" view on top of the current contents of the window.

    Transparent Modal View on Navigation Controller - Stack Overflow

    Talk Funnel Blog Archive Semi-Modal (Transparent) Dialogs on the iPhone

    Either way, you don't use the presentModalViewController, but you do the view hierarchy management yourself. If you used a delegate protocol, you have to dispose of the delegate and the view controller instance yourself appropriately.

    I have done similar things before and pondering which way is the best for me...
    · ·
  • pufftissuepufftissue Posts: 58Registered Users
    edited September 2010
    yoichi wrote: »
    Apparently the reason is that the model view removes (replaces) the previous view from the window. So, even if the model view itself is semi-transparent, there is nothing to show underneath. That is the problem. Apparently this was proven.

    So people are suggesting to make a "modal" view to be inserted as the top view, or draw the "modal" view on top of the current contents of the window.

    Transparent Modal View on Navigation Controller - Stack Overflow

    Talk Funnel Blog Archive Semi-Modal (Transparent) Dialogs on the iPhone

    Either way, you don't use the presentModalViewController, but you do the view hierarchy management yourself. If you still used a delegate protocol, you have to dispose of the delegate and the view controller instance yourself appropriately.

    I have done similar things before and pondering which way is the best for me...

    7 months later, is there still no way to get transparency when presenting modal views? I mean, no easy built-in ways in the SDK?
    · ·
  • ahmedrahmedr Posts: 1New Users
    edited January 2011
    I know this is an old thread but I've come across some sample code that implements showing a semi-transparent view by using UIActionSheet with no buttons.
    MyViewController *myVC = [[myViewController alloc] init];
    	UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"\n\n" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"done" otherButtonTitles:nil];
    	[myActionSheet addSubview:myVC.view];
    	[myActionSheet showInView:currentView];
    	[myActionSheet release];
    
    

    you must have a handle (currentView) of the view you and to add the semi-transparent view to.
    · ·
  • 2five72five7 Posts: 3New Users
    edited August 2011
    TomWhitson wrote: »
    Hi all,

    I want to pop up and animated modal view (with controller) over my current view. I have that working fine using a .xib file and some code like

    [PHP]
    ModalViewController *popupController = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];
    [self presentModalViewController:popupController animated:YES];

    [/PHP]

    What I would like to do is for the modal view to have a semi-transparent background image so that the views underneath can still be seen. I have used a semi transparent image as a background but it doesn't work. Has any one experienced this? Or is there some standard code/way to do this.

    Cheers,
    Tom

    Hi, You can check this link
    reednj - iOS: Semi-modal date picker for iPhone
    There is a beautiful example given about modalviewcontrollers with semi transparent background. Hope this serves your purpose.:D:D:D
    · ·
Sign In or Register to comment.