我已经看到了几个如何UIStoryboardSegue
使用自定义动画呈现自定义的示例。基本上,您继承UIStoryBoardSegue
并覆盖“执行”方法,即像这样:
- (void)perform
{
UIViewController *source = self.sourceViewController;
UIViewController *destination = self.destinationViewController;
// Create a UIImage with the contents of the destination
UIGraphicsBeginImageContext(destination.view.bounds.size);
[destination.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *destinationImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Add this image as a subview to the tab bar controller
UIImageView *destinationImageView = [[UIImageView alloc] initWithImage:destinationImage];
[source.parentViewController.view addSubview:destinationImageView];
// Scale the image down and rotate it 180 degrees (upside down)
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(0.1, 0.1);
CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(M_PI);
destinationImageView.transform = CGAffineTransformConcat(scaleTransform, rotateTransform);
// Move the image outside the visible area
CGPoint oldCenter = destinationImageView.center;
CGPoint newCenter = CGPointMake(oldCenter.x - destinationImageView.bounds.size.width, oldCenter.y);
destinationImageView.center = newCenter;
// Start the animation
[UIView animateWithDuration:0.5f
delay:0
options:UIViewAnimationOptionCurveEaseOut
animations:^(void) {
destinationImageView.transform = CGAffineTransformIdentity;
destinationImageView.center = oldCenter;
}
completion: ^(BOOL done) {
// Remove the image as we no longer need it
[destinationImageView removeFromSuperview];
// Properly present the new screen
[source presentViewController:destination animated:NO completion:nil];
}];
}
但是如果我在从屏幕上移除 Segue 的同时想要自定义动画该怎么办?覆盖这个类中的一些其他方法并调用它。还是在我叫“”的地方做动画,dismissViewController
感觉不合逻辑?
将不胜感激,
阿尔乔姆