开发者

How to rotate a UIImageView?

It's quite frustrating not to be able to do such a simple task: I have an "app" with a single viewcontroller, and in it a single UIImageView, that's initialized to a specific image at potrtait mode.

Now when the iPhone gets roteate开发者_JAVA百科d to landscape mode and the shouldAutorotateToInterfaceOrientation event fires, at which I return YES, my resulting UIImageView looks totally screwed up: either the image is stretched so to fill landscape mode frame (which looks ridiculuous of course) or the top and bottom of the image are cropped.

How can I have my UIImageview and the contained image handle the device rotation gracefully, and display normal looking image at landscape mode as well?


Set the image view's parent UIView autoresizesSubviews to YES.

Also set the autoresizingMask of the image view to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight


you also want to look into your UIImageView's contentMode. aspectFill and aspectFit behave very differently.


You can always subclass UIView and override the layoutSubviews method to manually lay out your subviews. The transition to landscape will still be animated, and you can do whatever you want with the subviews.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜