[英]iPhone center activity indicator regardless of screen orientation
无论屏幕方向如何,我如何以编程方式居中设置活动指示器?
尝试设置活动视图的center
属性,如下所示:
activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
在viewDidLoad
,注册设备轮换的通知:
- (void)viewDidLoad {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
并实现didRotate:
-(void)didRotate:(NSNotification *)notification {
if (activity) {
activity.center = CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2);
}
}
我建议你使用https://github.com/jdg/MBProgressHUD这是一个很棒的库,用于做各种“加载”屏幕。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.