![](/img/trans.png)
[英]Should SpriteKit games support both portrait and landscape orientations? Or, should they support only one of those orientations?
[英]Can we use same Xib (which contains UIView) to support both landscape and portrait orientations
我的故事板中有一個ViewController(searchListViewController)。 此ViewController嵌入在navigationController中。 當方向改變時,故事板中的ViewController可以正確旋轉。
我有一個包含UIView(CustomAlertView)的XIB。 我想從我的searchListViewController中呈現這個CustomAlertView。
為此,我在searchListViewController類中包含了以下代碼。
searchListViewController.m:
-(void)loadCustomAlertView
{
NSArray *allviews = [[NSBundle mainBundle] loadNibNamed:@"CustomAlertView" owner:self options:nil];
CustomAlertView *customAlertView_Obj = allviews[0];
[self.navigationController.view addSubview:customAlertView_Obj];
}
問題是:父導航控制器正確旋轉,但子方向“CustomAlertView”在方向更改時不會旋轉。 我在這段代碼中做錯了嗎?
無論如何以編程方式處理XIB文件的旋轉?
我想對Portrait和Landscape使用相同的CustomAlertView XIB。 可能嗎?
是的,您可以對兩個方向使用相同的xib文件。
使用自動調整大小/自動重新定位約束(在“大小檢查器”選項卡中)和自動布局(iOS6及更高版本),定義對象的屬性,以便在屏幕方向更改時,父視圖中的所有視圖都會對齊, /或重新定位,調整大小。
您可以通過更改“屬性檢查器選項卡”中的方向來查看視圖在不同方向的外觀。
只要你能做到addSubview:customAlertView_Obj
上searchListViewController
而不是增加對navigationController。
希望,它會奏效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.