开发者

Activity indicator not in center of the subview (which is not same size as parentview)

开发者 https://www.devze.com 2023-03-10 13:55 出处:网络
I am trying to c开发者_如何学Center a spinner in the middle of the page using the code below. self.aSpinner.center = self.view.center;

I am trying to c开发者_如何学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

Activity indicator not in center of the subview (which is not same size as parentview)

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.

Activity indicator not in center of the subview (which is not same size as parentview)

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?


[spinner setCenter:CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0)];


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消