2013-05-02 147 views
0

我正在使用故事板,並且想要爲我的應用添加彈出窗口。我彈出將包含一個滑塊(我需要得到他的價值),並取消選項('x'在彈出窗口頂部)。IOS-彈出故事板

這樣做的最好方法是什麼?

  • ViewController?
  • Xib文件?
  • 查看?

在此先感謝!

回答

0

我認爲這是最好創建一個彈出窗口,按鈕&您的代碼中的滑塊。比你有更多的控制權。訪問滑塊&可以更容易地解除相同代碼中的彈出窗口。

//Create a popovercontroller 
UIPopovercontroller *popOverController; 

//Create an instance of the class you working in, your viewcontroller 
YourViewController *popOverContent = [[YourViewController alloc] init]; 

//Create the popover view, you can change the size of it 
UIView *popOverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; 
UISLider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 200, 200)]; 
UIButton *close = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 20)] 

//Add slider & button to view 
[popOverView addSubview:slider]; 
[popOverView addSubview:button]; 

//Add view to viewcontroller 
[popOverContent addSubview:popOverView]; 

//Alloc & init the popovercontroller 
popOverController = [[UIPopoverController alloc] initWithContentViewController:popOverContent]; 

//Set content size of popover 
popOverController.popoverContentSize = CGSizeMake(200, 200); 

//present popup from a button or frame 
[popOverController presentPopoverFromRect:self.yourButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

比關閉按鈕創建一個IBAction爲,並使用此行代碼以關閉酥料餅:

按鈕時從那裏你想要的酥料餅的壓制將這個代碼在IBAction爲功能

[popOverController dismissPopoverAnimated:YES]; 

您可以找到有關popOverControllers更多信息here

0

取決於你想與您的彈出做什麼和怎麼做,你想呈現它,你可以選擇:

從故事板
  1. 的ViewController如果你想在modal style和你想要的彈出窗口出現一個彈出顯示其他視圖控制器。
  2. Xib文件的自定義UIView,如果您使用彈出窗口來顯示一些信息並獲得用戶輸入之後,您將關閉彈出窗口並彈出窗口將在幾個地方使用(不同的視圖控制器)
  3. Custom UIView的一個故事板視圖控制器,如果你想顯示一些信息和獲取用戶輸入並在彈出的將是使用只在一個地方(一個視圖控制器)