當用戶在行上點擊時,我在UItableviewcontroller上添加了pickerview。我正在使用以下代碼來顯示它。 [self.view.window addSubview:languagePicker];如何在設備改變方向時在屏幕上調整子視圖位置?
CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
CGSize pickerSize = CGSizeMake(768.0, 216.0);
CGRect startRect = CGRectMake(0.0,
screenRect.origin.y + screenRect.size.height,
pickerSize.width, pickerSize.height);
self.languagePicker.frame = startRect;
// compute the end frame
CGRect pickerRect = CGRectMake(0.0,
screenRect.origin.y + screenRect.size.height - pickerSize.height,
pickerSize.width,
pickerSize.height);
self.languagePicker.frame=startRect;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationOptionTransitionNone forView:self.view.window cache:YES];
[self.languagePicker setFrame:pickerRect];
[UIView commitAnimations];
它似乎工作完美的,當設備處於縱向,但只要方向改變了一切自我調整,除了增加的選擇器視圖。
我可以獲取設備方向,刪除舊的視圖,並根據方向添加新的視圖,但我不確定是否是一個好方法來做到這一點。我可以採取其他有效的方式嗎?
薩米特
你可以給我更多的細節或更多關於自動調整的指針嗎? – slonkar
請訪問:http://developer.apple.com/library/IOS/#documentation/UIKit/Reference/UIView_Class/UIView/UIView.html並查找autoresizingMask。 – samfisher
你可能想看看他的帖子也:http://stackoverflow.com/questions/3069388/uiview-autoresizingmask-problem – samfisher