首先在UIViewController的
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
方法中設置設備要支持的deviceOrientation;
在UIViewController的
-(void)willRotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
或者
-(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
duration:(NSTimeInterval)duration
重新設置所有子view的frame
當UIView設置成自動適配屏幕(即myView.autoresizesSubviews = YES)時,當我們重新設置myView的frame時(一般屏幕旋轉時我們都會重新設置view的frame),會自動調用layoutSubviers方法,我們可以在該方法中判斷屏幕的方向,並調整各子view的frame。
如果工層中有一個superViewController,然后在該控制器的試圖上加上了另一個subViewController的view,無論如何subViewController的以上三個方法都不會被調用,這個時候,可以在superViewController的
-(void)willRotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
或者
-(void)willAnimateRotationToInterfaceOrientation(UIInterfaceOrientation)interfaceOrientation
duration:(NSTimeInterval)duration
方法中重新配置subViewController的view。