它是公平地說,你要一個過渡,從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)創建一個UIImage財產上MyViewController2稱爲presentationImage,使它的setter公開。然後在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);
}];
}
以模態方式呈現第二個視圖控制器不會釋放執行呈現的視圖控制器。使用presentationViewController會給你一個指向該VC的指針 – jmstone617