Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone center activity indicator regardless of screen orientation

How can I center an activity indicator programmatically regardless of screen orientation?

like image 690
Tim Avatar asked May 09 '11 02:05

Tim


2 Answers

Try setting the center property of your activity view, like this:

 activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);

In viewDidLoad, register for notifications for the device rotation:

- (void)viewDidLoad {
   [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
   [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(didRotate:)
        name:UIDeviceOrientationDidChangeNotification object:nil];
}

and implement didRotate:

-(void)didRotate:(NSNotification *)notification {   
   if (activity) {
    activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
    }
}
like image 169
sudo rm -rf Avatar answered Nov 20 '22 05:11

sudo rm -rf


I suggest you use https://github.com/jdg/MBProgressHUD Which is a great library for doing all kinds of "Loading" screens.

like image 45
Zepplock Avatar answered Nov 20 '22 03:11

Zepplock