gpt4 book ai didi

ios - 自定义缩放过渡不适用于模态演示

转载 作者:行者123 更新时间:2023-12-01 16:39:39 25 4
gpt4 key购买 nike

我正在尝试创建一个 缩放过渡 .当它用于“插入”时,我让它工作得很好。现在我需要为模态转换工作,当然它不能只是一个 2 分钟的修复。

转换是从一个 NavigationController给另一个。我还是不明白ViewController键指向NavigationControllers ,他们应该指向实际的ViewControllers ?

这正是我想要的,但是 viewWillAppear在提供的 Controller 上永远不会被调用,NavigationBar也不觉得出现。

请帮我。我会给出我必须得到答案的每一分!

下面是动画方法:

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
UINavigationController *fromNav = (id)[transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UINavigationController *toNav = (id)[transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

UIViewController<SWZoomTransitionDelegate> *fromVC= (UIViewController<SWZoomTransitionDelegate> *)fromNav.topViewController;
UIViewController <SWZoomTransitionDelegate> *toVC = (UIViewController<SWZoomTransitionDelegate> *)toNav.topViewController;

UIView * containerView = [transitionContext containerView];
UIView * fromView = [fromVC view];
UIView * toView = [toVC view];

[containerView addSubview:toView];

UIView * zoomFromView = [fromVC viewForZoomTransition];
UIView * zoomToView = [toVC viewForZoomTransition];

UIImageView * animatingImageView = [self initialZoomSnapshotFromView:zoomFromView
destinationView:zoomToView];

if ([fromVC respondsToSelector:@selector(initialZoomViewSnapshotFromProposedSnapshot:)])
{
animatingImageView = [fromVC initialZoomViewSnapshotFromProposedSnapshot:animatingImageView];
}

animatingImageView.frame = [zoomFromView.superview convertRect:zoomFromView.frame
toView:containerView];

fromView.alpha = 1;
toView.alpha = 0;
zoomFromView.alpha = 0;
zoomToView.alpha = 0;
[containerView addSubview:animatingImageView];

ZoomAnimationBlock animationBlock = nil;
if ([fromVC respondsToSelector:@selector(animationBlockForZoomTransition)])
{
animationBlock = [fromVC animationBlockForZoomTransition];
}

[UIView animateKeyframesWithDuration:self.transitionDuration
delay:0
options:self.transitionAnimationOption
animations:^{
animatingImageView.frame = [zoomToView.superview convertRect:zoomToView.frame toView:containerView];
fromView.alpha = 0;
toView.alpha = 1;

if (animationBlock)
{
animationBlock(animatingImageView,zoomFromView,zoomToView);
}
} completion:^(BOOL finished) {
if ([transitionContext transitionWasCancelled]) {
[toView removeFromSuperview];
[transitionContext completeTransition:NO];
zoomFromView.alpha = 1;
} else {
[fromView removeFromSuperview];
[transitionContext completeTransition:YES];
zoomToView.alpha = 1;
}
[animatingImageView removeFromSuperview];
}];
}

最佳答案

我在另一个项目中遇到了类似的问题。调用viewWillAppear:根据the WWDC session,绝对是预期的行为:

And so as an interactive transition starts, the machinery behind in UIKit is actually going to be making calls out to view will appear, view will disappear, will show view controller, all the stuff that you've normally used to kind of control what's happening in your application as things come on and off screen.



就我而言,问题是动画对象在过渡期间被释放。我是这样设置动画师的:
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented
presentingController:(UIViewController *)presenting
sourceController:(UIViewController *)source {

AGBAnimator *animator = [AGBAnimator new];
return animator;
}

该对象超出范围并在动画期间被释放。通过创建 strong属性(property)和分配 animator在从此方法返回之前,问题已解决, viewWillAppear:等被成功调用。

关于ios - 自定义缩放过渡不适用于模态演示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25465560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com