在橫豎屏切換時(shí),每個(gè)控件重新布局。
首先創(chuàng)建兩個(gè)視圖:
IBOutlet?UIView?*hView;
IBOutlet?UIView?*vView;
創(chuàng)建相應(yīng)的@property方法.
然后在IB中在復(fù)制一個(gè)view。
把一個(gè)視圖做橫屏?xí)r的布局,一個(gè)view做豎屏?xí)r的布局。把相應(yīng)的view和相應(yīng)的方法相連接,在設(shè)置一個(gè)默認(rèn)視圖為view。
下面就是代碼實(shí)現(xiàn):
-?(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation?{?
????????if?(interfaceOrientation==UIInterfaceOrientationLandscapeLeft)?{?
????????????//zuo?
????????????self.view=self.hView;?
???????????}?
????????if?(interfaceOrientation==UIInterfaceOrientationLandscapeRight)?{?
????????????//you?
????????????self.view=self.hView;?
??????????}?
????????if?(interfaceOrientation==UIInterfaceOrientationPortrait)?{?
????????????//shang?
????????????self.view=self.vView;?
???????????}?
????????if?(interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)?{?
????????????//xia?
????????????self.view=self.vView;?
??????????}?
????????return?YES;?
????}