2

I want to change the position of UIImageView and button in view controller when status bar height will be increased.

I have changed the view frame by comparing status bar height and I also know that below method will be called when status bar frame will be changed but it will be called in delegate.

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame
- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame

but I want to change position of image view & button in view controller so how can I do that?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Aakil Ladhani
  • 984
  • 9
  • 32
  • 2
    i found the solutions by implementing below method: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeframe) name:UIApplicationWillChangeStatusBarFrameNotification object:nil]; – Aakil Ladhani Mar 13 '12 at 10:06

2 Answers2

0

You can observe UIApplicationWillChangeStatusBarFrameNotification or UIApplicationDidChangeStatusBarFrameNotification.

kelin
  • 11,323
  • 6
  • 67
  • 104
0

You can create a public method in your view to change the position when one of those methods trigger, something like:

-(void)changePosition {
myImageView.frame = CGRectMake(newPosition.x, newPosition.y, myImageView.frame.size. width, myImageView.frame.size.height) 

myButton.frame = CGRectMake(newPosition.x, newPosition.y, myButton.frame.size. width, myButton.frame.size.height) 
}

To make it public, create it in the .h file, something like:

@interface MyView : UIViewController {
}

-(void)changePosition;
@end

And then you call from your delegate:

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame{

[myView changePosition];

}
Antonio MG
  • 20,382
  • 3
  • 43
  • 62
  • i think for that the method would be class method like which should have + instead of - ahead of that method... – Aakil Ladhani Mar 13 '12 at 08:55
  • If you put + you would do a static method – Antonio MG Mar 13 '12 at 09:51
  • 1
    thanx but i found another solution by implementing below method: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeframe) name:UIApplicationWillChangeStatusBarFrameNotification object:nil]; – Aakil Ladhani Mar 13 '12 at 10:05