实现自定义动画以从 iPad 上的指定视图呈现模态视图 [英] Implement custom animation to present modal view from specified view on iPad
问题描述
在 iPad 上,我们有更多的工作空间,因此呈现全屏模式视图并不理想.
On the iPad we get much more room to work with, so presenting full screen modal views is not ideal.
我知道如何在新的 formSheet 中呈现模态视图,并且可以在这个问题上找到一个接近的方法:iPadiTunes 动画
I know how to present modal views in the new formSheet and a close approach can be found on this question: iPad iTunes Animation
问题是你不能选择动画的来源,所以它只是默认并从中心出现,我想自定义它以便它从特定位置出现.
The problem is that you cannot choose where the animation will come from, so it just defaults and appears from the center, I want to customize it so that it appears from a specific location.
我可以在this视频
如果有人可以使用代码、教程或文档为我指明正确的方向,我将不胜感激!
If anyone can point me on the right direction using code, tutorials or documentation I would greatly appreciate it!
更新:
经过一些调查,我发现这可以在第一部分使用图层和核心动画来完成;然后将其动画化为 formSheet 模态视图,但我仍然不太明白如何实现它,希望你们能提供帮助!
After some investigation I have found that this can be done using layers and Core Animation for the first part; and then animate it a formSheet modal view but I still dont quite understand how to achieve it, hopefully you guys can help!
推荐答案
我所做的是为 UIViewController 创建一个新类别,如下所示
What I did was creating a new category for UIViewController as follows
UIViewController+ShowModalFromView.h
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
@interface UIViewController (ShowModalFromView)
- (void)presentModalViewController:(UIViewController *)modalViewController fromView:(UIView *)view;
@end
UIViewController+ShowModalFromView.m
#import "UIViewController+ShowModalFromView.h"
@implementation UIViewController (ShowModalFromView)
- (void)presentModalViewController:(UIViewController *)modalViewController fromView:(UIView *)view
{
modalViewController.modalPresentationStyle = UIModalPresentationFormSheet;
// Add the modal viewController but don't animate it. We will handle the animation manually
[self presentModalViewController:modalViewController animated:NO];
// Remove the shadow. It causes weird artifacts while animating the view.
CGColorRef originalShadowColor = modalViewController.view.superview.layer.shadowColor;
modalViewController.view.superview.layer.shadowColor = [[UIColor clearColor] CGColor];
// Save the original size of the viewController's view
CGRect originalFrame = modalViewController.view.superview.frame;
// Set the frame to the one of the view we want to animate from
modalViewController.view.superview.frame = view.frame;
// Begin animation
[UIView animateWithDuration:1.0f
animations:^{
// Set the original frame back
modalViewController.view.superview.frame = originalFrame;
}
completion:^(BOOL finished) {
// Set the original shadow color back after the animation has finished
modalViewController.view.superview.layer.shadowColor = originalShadowColor;
}];
}
@end
很简单.如果这对您有帮助,请告诉我.
It's pretty straight forward. Please let me know if this helps you.
更新
我已经更新了使用动画块而不是 [UIView beginAnimations:nil context:nil];
/[UIView commitAnimations]
对的答案.
I've updated the answer to use animation blocks instead of [UIView beginAnimations:nil context:nil];
/ [UIView commitAnimations]
pair.
这篇关于实现自定义动画以从 iPad 上的指定视图呈现模态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!