我有一個iPad應用程序與分割視圖控制器。爲什麼detailViewController框架總是返回我1024 * 768
我想programmaticaly創建並添加子視圖到detailViewController在右下角。這樣做,我試圖讓的DetailView的框架(應用程序支持自動旋轉,所以那個位置不是靜態的)
我接下來做
在viewWillAppear中爲的DetailView我試圖讓幀,並計算位置,我需要
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
CGRect btnRect = self.view.frame;
//it always return 1024*748 width and height
//even in landscape mode
//when as i think must return 1024-321=703*748 pxls
//where is my mistake? How i can get actual frame
//dimensions for detailViewController in landscape orientation
btnRect.origin.y = btnRect.size.height - 42;
btnRect.origin.x = btnRect.size.width - 42;
btnRect.size.height = 42;
btnRect.size.width = 42;
UIButton* btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:someimage forState:UIControlStateNormal];
[[btn layer] setFrame:btnRect];
[self.view addSubview:btn];
}
但它總是告訴我detailView框架有1024 * 748尺寸。在風景模式下,我認爲它必須是703 * 748。我需要做什麼來獲得實際的detailView框架?
有你在代碼中設置或Interface Builder中右自動調整大小面具? – jbat100
不是。最佳做法是什麼? –
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;或在界面生成器中(在視圖的維度選項卡中) – jbat100