我使用UIViewController來顯示我的視圖。我的視圖已經在界面構建器中創建。錯誤的視圖大小ios
現在這些都是視圖下參數:
寬度:568 高度:320 方向:橫向
中的ViewController我有下一個代碼:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
在info.plist中我剛剛添加了兩個界面方向。
但是當我試圖在代碼中輸出我的視圖的寬度時,我得到320,當我嘗試輸出高度時,它在控制檯568中記下,但我期望320。
我不知道它爲什麼這樣工作。有什麼建議麼?
即使我補充一點:在viewDidLoad方法
[self.view setFrame:CGRectMake(0, 0, 568, 320)];
。即使這樣,我也inccorect高度
我需要知道的寬度尺寸我這個方法使用:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
CGFloat width = 0.0f;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
width = 568.0f;
} else {
width = 1024.0f;
}
NSInteger page = scrollView.contentOffset.x/width;
NSLog(@"%d", page);
}
現在我用寬度的硬編碼變量,但怎麼來的。爲什麼我不能使用self.view.frame.size.width
,因爲雙方互相交換 - 因爲。
讓我告訴你'UIInterfaceOrientationIsLandscape()'宏的存在性,更具可讀性。 – 2012-11-01 20:07:20
您可以粘貼您使用的代碼來打印視圖的寬度,以及視圖生命週期中該代碼正在執行的哪個點(加載,willapar,顯示後,...) –
NSLog( @「%f」,self.view.frame.size.height);我需要在UIScrollView deleagte中計算scrollViewDidEndDecelerating –