我正在創建iOS應用程序。它在導航控制器內運行。在我最近建立的視圖中,UITextViews
和UIImageView
錯誤地顯示在錯誤的座標上。我相信這可能是由於UINavigationBar
。對象在視圖中和設備方向更改後的位置不正確
當我在界面生成器中設置了鏡像的視圖時,實際上 顯示錯誤的視圖。我再次假設這是由於UINavigationBar
。我設法通過改變Interface Builder座標來「解決」這個問題,直到它正確顯示。這就是界面生成器現在的樣子:
我希望視圖可以在兩種設備方向(縱向和橫向)中工作。視圖中的對象不易被告知旋轉,所以我以編程方式定位視圖。代碼如下:
-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationPortrait) {
appInfo.frame = CGRectMake(20, 19, 280, 90);
updateInfo.frame = CGRectMake(20, 117, 280, 86);
authorInfo.frame = CGRectMake(20, 229, 172, 200);
authorImage.frame = CGRectMake(190, 274, 110, 110);
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
appInfo.frame = CGRectMake(11, 44, 199, 124);
updateInfo.frame = CGRectMake(218, 53, 242, 124);
authorInfo.frame = CGRectMake(11, 180, 340, 90);
authorImage.frame = CGRectMake(350, 170, 110, 110);
}
}
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
-(void) viewWillAppear:(BOOL)animated {
[self adjustViewsForOrientation:self.interfaceOrientation];
[super viewWillAppear:animated];
}
這裏是我的主要問題: 當視圖旋轉爲橫向,對象不直接定位。它們不遵循在旋轉過程中要調用的座標中描述的內容。
我怎樣才能解決此問題:當旋轉回縱向也發生
這個問題?預先感謝您。
你有任何的自動佈局中開啓這個觀點這有可能是你的幀變化而引起的自動佈局變得混亂 – gaige
沒有。我已經把所有這些都關掉了,假設你的意思是界面生成器中的方向更改設置 – DGund
不,我懷疑他的意思是在IB中自動設置大小。 – Rob