我想实例化一个viewController并将其放在当前显示的视图后面。然后移动原始视图的框架以显示其背后的视图。
我不能先创建底部视图并在顶部添加顶视图。我将创建多个底视图,内存不能同时处理整个堆栈。
我已遇到的问题。
presentViewController
deallocs原始视图(如果我以模态方式添加)有人可以帮忙吗?还是引导我走向一个方向?
答案 0 :(得分:1)
说你想要从vc1过渡到vc2是否公平,你想要的是 vc2在vc1下面的外观,vc1滑出去揭示它?
如果是这样的话,那么从sdk的角度来看,没有做任何不寻常或危险的事情是可行的。诀窍是执行正常的实例化和呈现步骤,但是在vc1中,在呈现vc2之前,将它呈现为看起来像vc1的UIImage。 Vc2在出现之前会覆盖该图像,然后将图像滑出以显示自身。
以下是步骤:
1)在vc1上,实现方法in this post。它捕获视图的图像。
2)有一些动作让你想要呈现vc2,就这样做......
- (void)presentVc2:(id)sender {
UIImage *image = [self makeImage]; // it was called makeImage in the other post, consider a better name
MyViewController2 *vc2 = [[MyViewController2 alloc] initWithNibName:@"MyViewController2" bundle:nil];
vc2.presentationImage = image; // more on this later
// this line will vary depending on if you're using a container vc, but the key is
// to present vc2 with NO animation
[self presentViewController:vc2 animated:NO completion:^{}];
}
3)在MyViewController2上创建一个名为presentationImage的UIImage属性,并将其设置为public。然后在MyViewController2 ...
// before we appear, cover with the last vc's image
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
UIImageView *imageView = [[UIImageView alloc] initWithImage:self.presentationImage];
imageView.frame = self.view.bounds;
imageView.tag = 128;
[self.view addSubview:imageView];
}
// after we appear, animate the removal of that image
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
UIImageView *imageView = (UIImageView *)[self.view viewWithTag:128];
[UIView animateWithDuration:0.5 animations:^{
imageView.frame = CGRectOffset(imageView.frame, -self.frame.size.width, 0);
}];
}
答案 1 :(得分:0)
您可以简单地将顶视图的内容放入一个新的UIView,其框架等于视图控制器的视图框架。然后将底部视图粘贴在容器视图下方。然后,移动容器视图将移动其所有内容,但保留底部视图。