tags:

views:

6818

answers:

2

I am displaying a model view with

[self presentModalViewController:controller animated:YES];

When the view moves up the screen it is transparent as per the setting in the xib file it is created from, but once it fills the screen it goes opaque.

Is there anyway of keeping the view transparent?

I suspect that the view it is being placed over is not being rendered rather then that the modal view is becoming opaque.

+8  A: 

Your view is still transparent, but once your modal controller is at the top of the stack, the veiw behind it is hidden (as is the case with any top -most view controller). The solution is to manually animate a view yourself; then the behind-viewController won't be hidden (since you won't have 'left' it).

Ben Gottlieb
Thanks, that confirms what I suspected.
Darryl Braaten
+7  A: 

For those who want to see some code, here's what I added to my transparent view's controller:

// Add this view to superview, and slide it in from the bottom
- (void)presentWithSuperview:(UIView *)superview {
    // Set initial location at bottom of superview
    CGRect frame = self.view.frame;
    frame.origin = CGPointMake(0.0, superview.bounds.size.height);
    self.view.frame = frame;
    [superview addSubview:self.view];            

    // Animate to new location
    [UIView beginAnimations:@"presentWithSuperview" context:nil];
    frame.origin = CGPointZero;
    self.view.frame = frame;
    [UIView commitAnimations];
}

// Method called when removeFromSuperviewWithAnimation's animation completes
- (void)animationDidStop:(NSString *)animationID
                finished:(NSNumber *)finished
                 context:(void *)context {
    if ([animationID isEqualToString:@"removeFromSuperviewWithAnimation"]) {
        [self.view removeFromSuperview];
    }
}

// Slide this view to bottom of superview, then remove from superview
- (void)removeFromSuperviewWithAnimation {
    [UIView beginAnimations:@"removeFromSuperviewWithAnimation" context:nil];

    // Set delegate and selector to remove from superview when animation completes
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

    // Move this view to bottom of superview
    CGRect frame = self.view.frame;
    frame.origin = CGPointMake(0.0, self.view.superview.bounds.size.height);
    self.view.frame = frame;

    [UIView commitAnimations];    
}
Kristopher Johnson
The only problem I have with this solution is memory management.For example:TestViewController *testView = [[TestViewController alloc]initWithNibName:@"TestView" bundle:nil];[testView presentWithSuperview:self.navigationController.view];Will work fine, however if you attempt to release or autorelease the View, any calls to methods within that view, will result in bad access exceptions
Mick Walker
Are you sure? I think the view will be retained by [superview addSubview:], so you should be able to release it.
Kristopher Johnson
If you call presentWithSuperview then release testView it crashes. It also displays displays "under" any NavigationController toolbars etc.
Ryan Booker