2013-08-21 55 views
1

我的通用應用程序使用NIB作爲其設置屏幕。我想爲iPhone和iPad使用相同的NIB。UIPopoverController內部移位框架

因此,在iPad上,我使用MainViewController中的UIPopoverController進行設置,只顯示iPhone大小的NIB,以顯示所謂的SettingsViewController。彈出窗口大小爲320x460點。

這會導致一個問題,因爲iPhone版本以編程方式在狀態欄上方繪製了許多東西,而對於iPad版本,這不是必需的。 iPad上的現狀:

enter image description here

正如你所看到的,有上述的「設置」標題一大空白。因此,我想要的,是將視圖控制器約20分,上移的酥料餅內:

enter image description here

的酥料餅如MainViewController如下實例:

 settingsPopoverController = [[UIPopoverController alloc] initWithContentViewController:popoverNavigationController]; 
     settingsPopoverController.popoverContentSize = CGSizeMake(320, 460); 
     settingsPopoverController.delegate = self; 
     popoverNavigationController.navigationBarHidden = YES; 

在SettingsViewController,我設置框架如下:

- (void)viewDidLoad 
{ 
    self.contentSizeForViewInPopover = CGSizeMake(320, 460); 
} 

而後來在Settin gsViewController,我嘗試創建一個偏移量,如下所示:

- (void)viewWillLayoutSubviews 
{ 
    // shift it up 
    CGRect frame = self.view.frame; 
    frame.origin.y = -20; 
    [self.view setFrame:frame]; 
} 

這不會將內容向上移動一點。怎麼去?

澄清:我想下移popover顯示的「視口」。

回答

-1

嘗試:

myPopover.autoresizingMask=UIViewAutoresizingNone; 

或者:

myPopover.autoresizingMask=UIViewAutoresizingFlexibleHeight || UIViewAutoresizingFlexibleWidth; 

您也可以嘗試把你的代碼-(void)viewDidLayoutSubviews方法。 如果這個答案沒有幫助,儘量設置popoverLayoutMargins(屬性),而不是setFrame:例如:

popover.popoverLayoutMargins=UIEdgeInsetsMake (
CGFloat 50, //top 
CGFloat 50,//left 
CGFloat 50,//bottom 
CGFloat 50//right 
); 
+1

UIPopoverController沒有autoresizingMask屬性,不知道你的意思。 將代碼移動到viewDidLayoutSubview沒有任何影響。 –

+0

在IB嘗試將偏移約束的優先級設置爲最小值。 – Kepler

+0

您是否需要移動彈出窗口視圖或彈出窗口箭頭? – Kepler