我想在iOS中制作自定义展开控制器动画。如何将CGRect框架值传递给自定义过渡动画控制器
这是一个iPad应用程序,并在主屏幕上有一个大小为160 * 160的大方形按钮。我已经将模态连接连接到下一个视图控制器场景。我试图实现的是当我点击UIButton时,目标视图控制器应该从按钮扩展,并且动画完成后将全屏动画。
我已经子类NSObject和创建ExpandAnimationController,实现了transitionDuration和animateTransition方法。但是我坚持要确定目标视图控制器视图的初始框架。
我知道一个按钮我可以静态设置框架,但在场景中出现的位置有多个按钮,并且每个按钮都必须将模式切换到不同的视图控制器,而不是如何将按钮帧传递给动画控制器设置初始视图框架。
我这样做只是为了学习目的后,尝试raywanderlich的自定义视图控制器转换教程。所以现在的问题是将一个框架对象从“源控制器”传递给动画控制器。我已经搜索过,互联网没有太多的定制转换问题。任何帮助将不胜感激。
这里是我试过,在ExpandAnimationController代码,
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
// 1. Fetch all the required objects.
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIView *containerView = [transitionContext containerView];
CGRect finalFrame = toVC.view.frame;
// 2. Set initial frames.
// This is where I am stuck.
CGRect initialFrame = CGRectZero;
toVC.view.frame = initialFrame;
[containerView addSubview:toVC.view];
// 3. Do the animation.
NSTimeInterval duration = [self transitionDuration:transitionContext];
[UIView animateWithDuration:duration animations:^{
fromVC.view.alpha = 0.5;
toVC.view.alpha = 0.5;
toVC.view.frame = finalFrame;
} completion:^(BOOL finished) {
fromVC.view.alpha = 1.0;
toVC.view.alpha = 1.0;
toVC.view.frame = finalFrame;
[transitionContext completeTransition:YES];
}];
}
在我采用UIViewControllerTransitioningDelegate
源控制器,创建了一个ExpandAnimationController实例,并像下面使用,
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
return _expandAnimationController;
}
但之后 - prepareForSegue
被称为我想将发件人按钮帧传递给过渡动画控制器。
在此先感谢,快乐编码!
发布您的代码获得伊娃值,所以我们可以看到你做了什么至今 – Lefteris 2014-11-03 08:27:17
@Lefteris嘿,我已经编辑了帖子,并添加代码,你询问,检查。 – 2014-11-03 08:36:19