gpt4 book ai didi

ios - 如何在单独的 ViewController 中在 iOS 中制作弹出/对话框 View ?

转载 作者:可可西里 更新时间:2023-11-01 04:08:55 25 4
gpt4 key购买 nike

我正在做一个iOS游戏,我想实现这样的效果: pause popup 2 different controllers

我知道如何使用一个 View Controller 来做到这一点,但我的 View Controller 类已经充斥着大量代码,而且该屏幕的 Storyboard一团糟(实际上我有比上图更多的 View ,为了清楚起见,我只是隐藏了它们原因)。

所以我的问题是:有没有办法通过使用单独的 View Controller 来管理这个暂停弹出窗口来实现这一点?我需要一个不会关闭先前显示的屏幕的 segue。我想用 Storyboard来做到这一点。我尝试了“popover”segue,但它出现了一个我不想要的奇怪边框。

我还需要所有不受暂停 View Controller 管理的控件停止监听事件。我想用一个覆盖整个屏幕的黑色透明 View 作为暂停 View 的BG,并让它忽略事件。有没有更好的方法?

提前致谢。

最佳答案

如果想用storyboard来实现,很简单。

我附上 example code

1 - 在 Storyboard 中创建您的自定义 PauseViewController。使用全屏 View 、黑色、Alpha 0 和包含暂停控件的 subview 。创建相应的 .h 和 .m 文件

2 - 添加和链接您的控件 (UIButtons)。像这样添加一个 dismiss 方法。此方法将从层次结构中删除 View 并使其在关闭时更改 alpha 不可见。

- (IBAction)dismiss:(id)sender {
[UIView animateWithDuration:0.3f animations:^{
self.view.alpha = 0.0f;
} completion:^(BOOL finished) {
[self.view removeFromSuperview];
[self removeFromParentViewController];
}];
}

3 - 子类 UIStoryboardSegue 创建您自己的 segue 类。然后,用类似这样的东西覆盖 perform 方法。这只需要两个 Controller (源和目标)并通过动画将目标 View 放在源 View 上。

-(void)perform{
UIViewController *dst = [self destinationViewController];
UIViewController *src = [self sourceViewController];

// add the view to the hierarchy and bring to front
[src addChildViewController:dst];
[src.view addSubview:dst.view];
[src.view bringSubviewToFront:dst.view];

// set the view frame
CGRect frame;
frame.size.height = src.view.frame.size.height;
frame.size.width = src.view.frame.size.width;
frame.origin.x = src.view.bounds.origin.x;
frame.origin.y = src.view.bounds.origin.y;
dst.view.frame = frame;

[UIView animateWithDuration:0.3f animations:^{
dst.view.alpha = 0.5f;
}];
}

4 - 链接你的转场,选择自定义并插入自定义转场类名。

哒哒哒!

如果您需要其他详细信息,请查看示例代码或添加评论。

关于ios - 如何在单独的 ViewController 中在 iOS 中制作弹出/对话框 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16242986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com