开发者

Why does my UIView position change in ways I don't expect?

My iPad app does not do what I expect it to when launching and rotating views.

AppDelegate has mainController.vie开发者_C百科w as a sub-view and mainController has splashController.view as a sub-view

mainController responds to willAnimateRotationToInterfaceOrientation by calling it's sub-view controller method of the same name (and then the super method).

The splashController has an image view that's 1024 x 1024. So I'm trying to center it in the sub-view.

When rotating, I adjust the bounds of all the views (in the willAnimateRotation... method) like this:

Landscape 1024 x 768

Portrait 768 x 1024

Then I center the views in the same method as well, by dividing the above values.

I'm not worried about the details of the status bars 10 pixels at this point.

When the app is launched in portrait, and rotated to landscape, the app does as expected.

When I launch or rotate to landscape, the view gets all messed up. The image is too far to the left/top or right/bottom and even though I've changed the center. (and not adjusted the frame).

Why does this only happen for landscape left or right and not for portrait or portrait upside down?


No idea why this happens for some instances but not for others, however I think you might be able to make life much easier for yourself by simply setting the autoresizing mask for your splashView rather than intercepting the rotation and re-adusting the view.

try setting these at load time:

splashView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
splashView.contentMode = UIViewContentModeCenter;

and ditch your willAnimateRotate... code.

Dave

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜