views:

170

answers:

8

I'm trying to display transparent UINavigationBar on top of Scrollview.

This is actual result of code that I have written...

alt text

where as I'm expecting view to be displayed like below image, which happens after I slightly scroll the image.

alt text

Code :

 - (void) loadView {
    CGRect pagingScrollViewFrame = [self frameForPagingScrollView];

    pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
    pagingScrollView.pagingEnabled = YES;
    pagingScrollView.backgroundColor = [UIColor blackColor];
    pagingScrollView.showsVerticalScrollIndicator = NO;
    pagingScrollView.showsHorizontalScrollIndicator = NO;
    pagingScrollView.contentSize = CGSizeMake(pagingScrollViewFrame.size.width * [self imageCount], 
                                              pagingScrollViewFrame.size.height);
    pagingScrollView.delegate = self;

    self.wantsFullScreenLayout = YES;
    pagingScrollView.scrollsToTop = YES;
    self.view = pagingScrollView;
}

question is how do I make view to load as I expected without user interacting to it? any suggestion or help is appreciated..

EDIT: I'm creating view totally from CODE

+2  A: 

It seems like you're trying to do this in code not in the IB. If so, you have to put your code in the viewDidLoad of the Application Delegate (e.g. MyProgramAppDeligate class or whatever). If you want it in some certain views, put it in the viewDidLoad of the UINavigationController class/subclass.

Does this satisfy your requirement?

Mustafa
A: 

You have to set

self.navigationController.navigationBar.translucent = YES;

As soon as you do this, the 0,0 coordinate is behind your navigation bar not below it and your view shifts behind the bar.

Ortwin Gentz
So you are suggesting to add given code before I do `self.view = pagingScrollView;`
Prashant
yes, that's right.
Ortwin Gentz
I tried this but still no joy !
Prashant
A: 

It may be a conflict between IB and your code. I would add the line of code suggested by Ortwin in the viewDidLoad method and then double check you've set the navBar to translucent in IB.

Jonah
I did set in `viewDidLoad` method and even tried setting in `loadView`, nothing is helping
Prashant
Prashant, you should tell us how you created the view. Via code or IB? The fact you're using -loadView and not -viewDidLoad suggests you're doing it in code. But we need to know more in order to help.
Ortwin Gentz
A: 

The code you have posted has nothing to do with the opacity of the navigation bar. Show where you are setting the configuration of the components of the view. There you could just set the alpha of the navigation bar. Alternatively if you are using nibs, just set the alpha in IB.

dkk
setting the alpha shouldn't be necessary. Actually, it's wrong because it would affect the button and title text as well. The translucent property of the navigationBar is the way to go.
Ortwin Gentz
+1  A: 
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.tintColor = [UIColor blackColor];

And to make your statusbar translucent.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES]; 
[self setWantsFullScreenLayout:YES];

I have this inside my willWillAppear and I reset it in my viewWillDisappear.

Sander Backus
A: 

Since you say that it works fine after the user (you) slightly scrolls the image, the problem might be that the UINavigationBar's drawRect: method does not get called after the UIScrollView is loaded.

Suggestion: Can you explicitly call setNeedsDisplay on the navigation bar after the view is loaded?

user8472
A: 

Have you tried setting the frame of the scroll view with an Y origin of 0 after setting the nav bar to transparent?

EDIT: I mean, you don't say what's the frame used in your code.

jv42
A: 

In viewDidLoad, try moving the origin up 32 pixels and grow the height by 32 pixels as well:

pagingScrollView.frame = CGRectMake(pagingScrollView.frame.origin.x, pagingScrollView.frame.origin.y-32, pagingScrollView.frame.size.width, pagingScrollView.frame.size.height+32);
Peter DeWeese