gpt4 book ai didi

objective-c - 为什么 iOS7 的 animateTransition 中的 UIView transitionFromView 可以,但 iOS8 没有动画

转载 作者:搜寻专家 更新时间:2023-10-30 19:43:50 24 4
gpt4 key购买 nike

我想在 presentViewController 期间制作动画:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *toView = toVC.view;
UIView *fromView = fromVC.view;
UIView* containerView = [transitionContext containerView];
[containerView addSubview:toView];
NSTimeInterval duration = 0.35;
[UIView transitionFromView:fromView toView:toView duration:duration options:(self.reverse?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight) |
UIViewAnimationOptionAllowUserInteraction completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}

这在 iOS7 上工作正常,但在 iOS8 上没有动画。

最佳答案

+transitionFromView:toView:duration:options:completion:处理 View 层次结构的工作。你不应该需要 [containerView addSubview:toView]

+transitionFromView:toView:duration:options:completion: 内部的某处应该是以下代码:

UIView *superview = fromView.superview;
[fromView removeFromSuperview];
[superview addSubview:toView];

您是否尝试过删除 containerView 代码:

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
UIView *toView = toVC.view;
UIView *fromView = fromVC.view;
NSTimeInterval duration = 0.35;
[UIView transitionFromView:fromView toView:toView duration:duration options:(self.reverse?UIViewAnimationOptionTransitionFlipFromLeft:UIViewAnimationOptionTransitionFlipFromRight) |
UIViewAnimationOptionAllowUserInteraction completion:^(BOOL finished) {
[transitionContext completeTransition:![transitionContext transitionWasCancelled]];
}];
}

关于objective-c - 为什么 iOS7 的 animateTransition 中的 UIView transitionFromView 可以,但 iOS8 没有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24969916/

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