views:

372

answers:

1

I'm adding a custom status bar in my application to monitor upload progress. This works fine in portrait mode, but when I am in landscape and my custom status bar appears, it always appears on the opposite side of the home button. I think it's because I'm hard coding my frame.

I have the XIB file set to auto adjust its length.

take a look:

-(void) animateStatusBarIn {
float x = window.frame.origin.x;
float y = window.frame.origin.y;
float height = 20;
float width = window.frame.size.width;
CGRect statusFrame = CGRectMake(x, y-20, width, height);
iPadUploadStatusBar *statusView = [[iPadUploadStatusBar alloc] initWithNibName:@"iPadUploadStatusBar" bundle:nil];

self.status = statusView;

[statusView release];

status.view.frame = statusFrame;
[window addSubview:status.view];

[UIView beginAnimations:@"slideDown" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
statusWindow.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 20.0f);    
[UIView commitAnimations];
}   

All is good in portrait orientation, but like I said, it always decides that the new status bar should go opposite of the home button. Please help!!!

By the way, this is inside AppDelegate.m, so I'm using the existing window that's in the default appDelegate file Thanks

+1  A: 

Firstly, where are you calling your -animateStatusBarIn method from?

You dont have to set the frame for iPadUploadStatusBar's view when rotation occurs (in case if you are calling the method animateStatusBar each time when orientation changes).

All you have to do is, set the autoresizing masks for the view properly in your iPadUploadStatusBar nib and add it as a subview to window or a viewController's view which is already a subview of window. The rotation and its animation is all handled automatically for you.

Raj
I call animateStatusBarIn from an NSNotification that uploading has started. It's not being called on view rotation. The problem is, the frame is always a long rectangle opposite and perpendicular to the home button. So in portrait mode, it's fine, but in landscape mode it's on the side of the screen facing up and down. I have the view set to resize its width in IB, and the viewController supports all orientations
JustinXXVII
I have confirmed by writing a sample that rotation messages are sent only to the FIRST viewController whose view has been added to the window. So you are adding your view to window in -animateStatusBarIn method which is apparently not the first viewController's view in the window and hence it is not getting the rotation events.For more details, check the accepted answer of this question: http://stackoverflow.com/questions/548142/uiviewcontroller-rotate-methodsA solution for you is to keep separate space in your main viewController for statusBar and add "iPadUploadStatusBar" subview there.
Raj