问题描述
|
我正在尝试使用下面的代码在页面中间居中微调器。
self.aSpinner.center = self.view.center;
但是,当我运行程序时,微调器似乎不在中心
有没有什么办法解决这一问题?
编辑:
我发现了问题。并不是说微调器不在中心,而是子视图的边界与其父视图的边界不同。
我在我的代码中做了这样的事情:
self.navcon = [[UINavigationController alloc]init];
self.photoViewTable = [[PhotoTableViewController alloc]init];
self.loadingPage = [[LoadingPageViewController alloc]init];
[self.photoViewTable.view addSubview:loadingPage.view];
[navcon pushViewController:photoViewTable animated:NO];
[self.window addSubview:navcon.view];
如何设置loadingPage
视图的大小等于父视图?
解决方法
[spinner setCenter:CGPointMake(kScreenWidth/2.0,kScreenHeight/2.0)];
, 设置中心属性可能还不够。如果要调整框架的大小,我还将设置微调器视图的自动调整大小蒙版:
spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
spinner.center = CGPointMake(CGRectGetWidth(self.view.bounds)/2,CGRectGetHeight(self.view.bounds)/2);
, 尝试在ViewDidAppear上执行此操作,查看正确的self.bounds
我不检查self.center。
self.aSpinner.center = CGPointMake(self.view.bounds.width/2.0,self.view.bounds.width/2.0)
工作正常!
检查自身是否有视图或自身是否为视图