Always center UIView

Posted by bresc on Stack Overflow See other posts from Stack Overflow or by bresc
Published on 2010-06-15T13:19:12Z Indexed on 2010/06/15 13:22 UTC
Read the original article Hit count: 385

Filed under:
|
|
|
|

Hi,

I have a small UIView that should appear always in the center of the screen. This works great for portrait mode but does not in landscape.

To draw the UIView I use:

myView.frame = CGRectMake((visibleArea.size.width - MY_VIEW_WIDTH) / 2, (visibleArea.size.height - MY_VIEW_HEIGHT) / 2, MY_VIEW_WIDTH, MY_VIEW_HEIGHT);
myView.autoresizingMask = (
                            UIViewAutoresizingFlexibleTopMargin |
                            UIViewAutoresizingFlexibleBottomMargin |
                            UIViewAutoresizingFlexibleLeftMargin |
                            UIViewAutoresizingFlexibleRightMargin
                           );

Any ideas what might be missing?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk