UIView.center = UIImageView.center but image view doesn't seem to be in centre in landscape UIView.center = UIImageView.center but image view doesn't seem to be in centre in landscape ios ios

UIView.center = UIImageView.center but image view doesn't seem to be in centre in landscape


The center of a view is expressed in it's superview's coordinate system. So you are centering your image view in the wrong coordinate system. (dynamic view's superview as opposed to dynamic view)

To centre view A within view B, the centre point of view A has to be the centre of the bounds rectangle of view B. You can get this using (from memory!) CGRectGetMidX and CGRectGetMidY.


You should check the size of the image. Frame of the image may not be the frame of the UIImageView. Set the background color of the UIImageView to something like [UIColor redColor] and clipToBounds to true and see what'll happen. If there are red parts that are visible the problem is with the contentMode property of your imageView object.