gpt4 book ai didi

ios - 关闭两个模态视图 Controller

转载 作者:可可西里 更新时间:2023-11-01 03:40:00 26 4
gpt4 key购买 nike

我发现了几个与此相关的问题,但答案并没有解决我的问题。

我有两个使用 presentModalViewController 呈现的 Controller 。

我将 modalTransitionStyle 添加到主 Controller 调用的第一个 Controller 。第一个 Controller 正常呈现第二个 Controller (无过渡样式)。

FirstVC *first = [[FirstVC alloc] initWithNibName:@"FirstVC" bundle:nil];
first.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:first animated:YES];

SecondVC *second = [[SecondVC alloc] initWithNibName:@"SecondVC" bundle:nil];
[self presentModalViewController:second animated:YES];

这是我用来转到 MainVC 的代码:

[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];

事情是这样的:

enter image description here

页面没有展开。我遇到这种情况的原因是什么?

最佳答案

在我的实验中,您似乎无法在部分 curl 后进行标准演示(覆盖垂直),并同时关闭它们,除非您将动画设置为 NO 进行关闭。

解决这个问题的方法是关闭没有动画的 secondVC(此代码在 secondVC 中):

-(IBAction)dismissSelf:(id)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}

然后在 firstVC 中再次关闭 viewDidAppear 中的动画,在测试 Controller 没有被呈现之后:

-(void)viewDidAppear:(BOOL)animated {
if (![self isBeingPresented]) {
[self dismissViewControllerAnimated:YES completion:nil];
}
}

虽然上面的代码可以返回到初始 Controller 的 View ,但您会看到 firstVC 的 View 出现在 curl 展开之前。如果您不想看到它,那么我能找到解决该问题的唯一方法是创建 secondVC 的图像,将其作为(在 ImageView 中) subview 添加到 firstVC,然后再取消 secondVC。因此,要做到这一点,secondVC 中的代码应该是这样的(请注意,您必须链接到 QuartzCore 并将其导入 secondVC 才能工作):

-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIImage *img = [self imageWithView:self.view];
FirstViewController *first = (FirstViewController *)self.presentingViewController;
UIImageView *iv = [[UIImageView alloc] initWithFrame:first.view.bounds];
iv.image = img;
[first.view addSubview:iv];
}


-(IBAction)dismissSelf:(id)sender {
[self dismissViewControllerAnimated:NO completion:nil];
}


- (UIImage *)imageWithView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}

关于ios - 关闭两个模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18501691/

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