简体   繁体   中英

How to autorotate UIScrollView and UIImageView programmatically?

I have a UIScrollView and a UIImageView which I have created programmatically without interface builder. How can I make sure both auto-rotate in horizontal orientation?

If you're subclassing UIViewController, even programmatically, you should get rotation for free. Just make sure you set the autoresizingMask on the scroll view and image view so that the mask is set to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight if you want the view to adapt to the new screen dimensions.

make sure you have implemented shouldAutorotateToInterfaceOrientation and then do a little

yourView.transform = CGAffineTransformIdentity;
yourView.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); 

and using this in your header files can be very useful

#define degreesToRadian(x) (M_PI * (x) / 180.0)

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