gpt4 book ai didi

ios - 如何在其他 UIViewController 中显示 UIViewController?

转载 作者:行者123 更新时间:2023-11-29 13:11:50 25 4
gpt4 key购买 nike

这是一个典型的问题,可能会重复,但是..

iPad 应用有 UINavigationBarUITabBar。我在 navigationBar 上创建了一个按钮,它必须显示 appinfoViewController

当我展示它时,navigationBar 和 tabTab 仍然可以点击。但我想将 appinfoViewController 显示为完整应用程序的主屏幕尺寸(如模态)

这是我的代码:

- (void)showInfo
{
AboutViewController *about = [[AboutViewController alloc] init];
[about.view setFrame: self.view.frame];
[about.view setAlpha:0.0];

[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
[about.view setAlpha:1.0];

[self.view addSubview:about.view];
[self addChildViewController:about];
[about didMoveToParentViewController:self];
}
completion:^(BOOL finished){

}];
}

如何全屏显示appinfoViewController

是否可以在没有黑色背景的情况下以模态方式呈现它?

最佳答案

按照评论中的建议,使用

[self presentViewController:about animated:YES completion:nil]

会去掉导航栏和标签栏。如果你需要保留它们,你需要使用

[self.navigationController pushViewController:about animated:YES];

编辑:

为了在除了您的关于 View 之外的任何地方都禁用用户交互,它有点棘手:首先,您需要将所有 UI 元素嵌入到一个 View 中,该 View 不是呈现 View Controller 的主视图。

假设您只有一个按钮(“显示关于”按钮),您不会只是将它放在主视图中,而是使用另一个 View (我们称之为“外部 View ”)与 View Controller 的 View 以及放置按钮的位置(以及您可能拥有的任何其他 ui 元素)一样大。您还需要一个导出到这个外部 View 。然后写一个方法如:

-(void)userInteractionEnabled:(BOOL)enabled
{
self.navigationController.navigationBar.userInteractionEnabled = enabled;
self.tabBarController.tabBar.userInteractionEnabled = enabled;
self.outerView.userInteractionEnabled = enabled;
}

或者,您可以简单地禁用每个“交互式” socket 而不是 outerView。因此,例如,如果您有 2 个 TextView 、3 个按钮和一个 UIPickerView,您将为每个导出设置 userInteractionEnabled = enabled(而不是仅为父 View 设置)。

现在,在您的 showInfo 方法中您可以:

 CGRect frame = CGRectMake(50, 50, 200, 200); //Use whatever origin and size you need
about.view.frame = frame;
[self.view addSubview:about.view];
[self userInteractionEnabled:NO]

在您的 btnClose 方法中,您可以输入:

[about.view removeFromSuperview];
[self userInteractionEnabled:YES];

希望这对您有所帮助,如果这正是您所需要的,请告诉我!

附言也许您已经意识到这一点,但是有一个类 UIPopoverController,仅适用于 iPad 的应用程序,它几乎可以为您完成所有这些工作。您可以找到有关如何使用它的教程 here .

关于ios - 如何在其他 UIViewController 中显示 UIViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17104662/

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