简体   繁体   中英

ios [[self view] center].x

on the ipad, when in portrait(not sure if you call it this) the [[self view] center].x value is in the center - but when in landscape(lying down) it is not the center value.

Any idear?

Thanks

The center property of a view is relative to its superview , which is probably the UIWindow in your case. Since rotation is handled by the view controller and the window actually doesn't rotate, the center of your view stays the same.

What you probably want instead is the center of your view's bounds:

CGRect bounds = self.view.bounds;
CGPoint centerOfView = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM