7
无论屏幕方向如何,我如何以编程方式将活动指示器置于中心位置?与屏幕方向无关的iPhone中心活动指示器
无论屏幕方向如何,我如何以编程方式将活动指示器置于中心位置?与屏幕方向无关的iPhone中心活动指示器
尝试设置你的活动视图的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 这是一个伟大的图书馆,用于做各种“加载”屏幕。
当我旋转屏幕时它仍然会居中吗?谢谢 – Tim 2011-05-09 02:07:29
不,你一旦注册它就必须重新居中。所以基本上只是在收到轮换通知时重新居中。欢迎来到Stack Overflow。 :) – 2011-05-09 02:09:30
如何以及在哪里让它重新居中?我开始喜欢这个地方 – Tim 2011-05-09 02:17:44