活动指示器不在子视图的中心(与父视图的大小不同)

发布于 2024-11-12 23:16:36 字数 821 浏览 0 评论 0原文

我正在尝试使用下面的代码将旋转器置于页面中间的中心。

self.aSpinner.center = self.view.center;

但是,当我运行该程序时,旋转器似乎不在中心

iPad 模拟器的屏幕截图;活动指示器为空白查看中心右侧

有什么办法可以解决这个问题吗?

编辑:

我发现了问题。这并不是说旋转器不在中心,而是子视图与其父视图具有不同的边界。

iPad 模拟器的屏幕截图;查看子视图和活动指示器位于中心右侧

我在代码中做了类似的事情:

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 视图的大小设置为等于父视图吗?

I am trying to center a spinner in the middle of the page using the code below.

self.aSpinner.center = self.view.center;

However when when I run the program, the spinner does not seem to be in the center

Screen shot of iPad simulator; activity indicator in blank view to right of center

Is there any way to fix this?

EDIT:

I found the problem. It's not that the spinner is not in the center, but instead the subview has different bounds than its superview.

Screenshot of iPad simulator; view with subviews and activity indicator to right of center

I am doing something like this in my code:

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];

How can I set the size of loadingPage view to be equal to the parent view?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最单纯的乌龟 2024-11-19 23:16:36
[spinner setCenter:CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0)];
[spinner setCenter:CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0)];
卖梦商人 2024-11-19 23:16:36

设置中心属性可能还不够。如果您的框架正在调整大小,我还将设置微调器视图的自动调整大小蒙版:

spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                              UIViewAutoresizingFlexibleRightMargin |
                                              UIViewAutoresizingFlexibleTopMargin |
                                              UIViewAutoresizingFlexibleBottomMargin);
spinner.center = CGPointMake(CGRectGetWidth(self.view.bounds)/2, CGRectGetHeight(self.view.bounds)/2);

Setting the center properties might not be enough. In case your frame is being resize i will also set the autoresize mask of the spinner view:

spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                              UIViewAutoresizingFlexibleRightMargin |
                                              UIViewAutoresizingFlexibleTopMargin |
                                              UIViewAutoresizingFlexibleBottomMargin);
spinner.center = CGPointMake(CGRectGetWidth(self.view.bounds)/2, CGRectGetHeight(self.view.bounds)/2);
只是在用心讲痛 2024-11-19 23:16:36

尝试在 ViewDidAppear 上执行此操作,视图有正确的 self.bounds
我不检查 self.center。

self.aSpinner.center = CGPointMake(self.view.bounds.width/2.0, self.view.bounds.width/2.0)

工作正确!
检查自身是否有视图或自身是否被查看

Try do it on ViewDidAppear, there is correct self.bounds of view
I don't check self.center.

self.aSpinner.center = CGPointMake(self.view.bounds.width/2.0, self.view.bounds.width/2.0)

Work correct!
Check self has view or self is view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文