IOS-弹出故事板

问题描述:

我正在使用故事板,并且想要为我的应用添加弹出窗口。我弹出将包含一个滑块(我需要得到他的价值),并取消选项('x'在弹出窗口顶部)。IOS-弹出故事板

这样做的最好方法是什么?

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

在此先感谢!

我认为这是最好创建一个弹出窗口,按钮&您的代码中的滑块。比你有更多的控制权。访问滑块&可以更容易地解除相同代码中的弹出窗口。

//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

取决于你想与您的弹出做什么和怎么做,你想呈现它,你可以选择:

从故事板
  1. 的ViewController如果你想在modal style和你想要的弹出窗口出现一个弹出显示其他视图控制器。
  2. Xib文件的自定义UIView,如果您使用弹出窗口来显示一些信息并获得用户输入之后,您将关闭弹出窗口并弹出窗口将在几个地方使用(不同的视图控制器)
  3. Custom UIView的一个故事板视图控制器,如果你想显示一些信息和获取用户输入并在弹出的将是使用只在一个地方(一个视图控制器)