我不确定,但我认为你不应该在来自 B 时向 A 添加视图,问题可能就在那里。而是在 B 上添加两个视图。
此代码有效:
//ZoomInSegue.m
- (void)perform {
UIViewController* source = (UIViewController *)self.sourceViewController;
UIViewController* destination = (UIViewController *)self.destinationViewController;
//Custom method to create an UIImage from a UIView
UIImageView * destView = [[UIImageView alloc] initWithImage:[self imageWithView:destination.view]];
CGRect destFrame = destView.frame;
destFrame.origin.x = destination.view.frame.size.width/2;
destFrame.origin.y = destination.view.frame.size.height/2;
destFrame.size.width = 0;
destFrame.size.height = 0;
destView.frame = destFrame;
destFrame = source.view.frame;
[source.view addSubview:destView];
[UIView animateWithDuration:1.0
animations:^{
destView.frame = destFrame;
}
completion:^(BOOL finished) {
[destView removeFromSuperview];
[source.navigationController pushViewController:destination animated:NO];
}];
}
//ZoomOutSegue.m
- (void)perform {
UIViewController* source = (UIViewController *)self.sourceViewController;
UIViewController* destination = (UIViewController *)self.destinationViewController;
//Custom method to create an UIImage from a UIView
UIImageView* sourceView = [[UIImageView alloc] initWithImage:[self imageWithView:source.view]];
CGRect sourceFrame = sourceView.frame;
sourceFrame.origin.x = source.view.frame.size.width/2;
sourceFrame.origin.y = source.view.frame.size.height/2;
sourceFrame.size.width = 0;
sourceFrame.size.height = 0;
[source.view addSubview:destination.view];
[source.view addSubview:sourceView];
[UIView animateWithDuration:1.0
animations:^{
sourceView.frame = sourceFrame;
}
completion:^(BOOL finished) {
[source.navigationController popViewControllerAnimated:NO];
}];
}