2016-10-25 61 views

回答

0

添加和使用didRotateFromInterfaceOrientation方向委託方法。

佈局子視圖使用的UIViewautoresizingMask財產,

一樣,

YourView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

UIView documentation

當一個視圖邊界的變化,這種觀點將自動調整根據其 子視圖到每個子視圖的自動調整掩碼。

autoresizingMask更改爲None以外的值將觸發layoutSubviews

因此,您可以使用didRotateFromInterfaceOrientation委託方法使用下面的代碼來佈局子視圖。

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 

    [self.view layoutIfNeeded]; 
    [self.view setNeedsLayout]; 
    self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

    //....Other code 
} 


-(void)layoutSubviews{ 

    //write your code to draw here 
} 
相關問題