How can I center an activity indicator programmatically regardless of screen orientation?
无论屏幕方向如何,我如何以编程方式居中显示活动指示器?
2 个解决方案
#1
12
Try setting the center
property of your activity view, like this:
尝试设置活动视图的center属性,如下所示:
activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
In viewDidLoad
, register for notifications for the device rotation:
在viewDidLoad中,注册设备轮换的通知:
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
and implement didRotate:
并实现didRotate:
-(void)didRotate:(NSNotification *)notification {
if (activity) {
activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
}
}
#2
1
I suggest you use https://github.com/jdg/MBProgressHUD Which is a great library for doing all kinds of "Loading" screens.
我建议你使用https://github.com/jdg/MBProgressHUD这是一个很棒的库,用于做各种“加载”屏幕。
#1
12
Try setting the center
property of your activity view, like this:
尝试设置活动视图的center属性,如下所示:
activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
In viewDidLoad
, register for notifications for the device rotation:
在viewDidLoad中,注册设备轮换的通知:
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
and implement didRotate:
并实现didRotate:
-(void)didRotate:(NSNotification *)notification {
if (activity) {
activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
}
}
#2
1
I suggest you use https://github.com/jdg/MBProgressHUD Which is a great library for doing all kinds of "Loading" screens.
我建议你使用https://github.com/jdg/MBProgressHUD这是一个很棒的库,用于做各种“加载”屏幕。