Reputation: 12366
I've found that with album orientation on iPhones status bar disappears. My views were adjusted just below status bar using .frame
property. Now, when status bar disappears, I want to move them higher. What's correct way to do that? Also on iPads status bar doesn't disappear so I would like some kind of universal way to handle that.
Currently I can overload viewWillTransitionToSize:withTransitionCoordinator:
in my controller and adjust settings there. But I can't found whether status bar will be hidden after transition or not.
I use .xib
files, not storyboards, if it matters.
Upvotes: 0
Views: 95
Reputation: 9609
I had same issue.I overcome this by following
Best to use
-(void)viewWillLayoutSubviews()
{
//........
}
method in your coding.It automatically lays out the view.It adjusts the size according the view orientation.I applied this method for iPhone and iPad.It works perfectly.
Before that you should follow the below things
1.plist
View controller-based status bar appearance boolean NO
in appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[UIApplication sharedApplication].statusBarHidden=NO;
[application setStatusBarStyle:UIStatusBarStyleLightContent];
[application setStatusBarHidden:NO];
}
In your ViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
//For iPAD I set the bounds because it calls this method,Once it returns from previous view controller or background to foreground
self.view.bounds = CGRectMake(0, -20, 1024, 768);
}
-(void)viewWillLayoutSubviews
{
self.view.clipsToBounds = YES;
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenHeight = 0.0;
screenHeight = screenRect.size.width;
CGRect screenFrame = CGRectMake(0, 20, self.view.frame.size.width,screenHeight-20);
CGRect viewFrame1 = [self.view convertRect:self.view.frame toView:nil];
if (!CGRectEqualToRect(screenFrame, viewFrame1))
{
self.view.frame = screenFrame;
self.view.bounds = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
NSLog(@"width is - %f",[[self view] bounds].size.width);
NSLog(@"height is - %f",[[self view] bounds].size.height);
}
}
Upvotes: 1