繁体   English   中英

iOS 7自定义过渡:将不进行动画处理

[英]iOS 7 Custom Transition: Will Not Animate

我希望您能对我有所帮助,我试图在我的应用程序中实现一个自定义过渡,该过渡将显示一个自定义模态视图控制器。 我能够使View Controller出现预期的效果,但是,我无法过渡到动画。 任何对此的帮助或指向正确方向的指针将不胜感激。

请在下面查看我的代码:

-(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{
    return 1.0;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    CGRect sourceRect = [transitionContext initialFrameForViewController:fromVC];

    fromVC.view.frame = sourceRect;

    UIGraphicsBeginImageContextWithOptions(fromVC.view.frame.size, NO, 0);
    [fromVC.view drawViewHierarchyInRect:fromVC.view.bounds afterScreenUpdates:YES];
    UIImage *fromVCImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIView *container = [transitionContext containerView];
    [container setBackgroundColor:[UIColor colorWithPatternImage:fromVCImage]];

    [container insertSubview:toVC.view belowSubview:fromVC.view];

    CGRect fromVCFrame = fromVC.view.frame;

    __block CGRect toVCFrame = toVC.view.frame;
    toVCFrame.origin.y = fromVCFrame.origin.y + fromVCFrame.size.height;
    [toVC.view setFrame:toVCFrame];
    [toVC.view setAlpha:0.0];
    [toVC.view setBackgroundColor:[UIColor colorWithPatternImage:fromVCImage]];

    [transitionContext finalFrameForViewController:toVC];

    //3.Perform the animation...............................
    [UIView animateWithDuration:1.0
                     animations:^{
                         toVCFrame.origin.y = fromVCFrame.origin.y;
                         toVC.view.frame = toVCFrame;

                         [toVC.view setAlpha:1.0];
                     }
                     completion:^(BOOL finished) {
                         //When the animation is completed call completeTransition
                         [transitionContext completeTransition:YES];
                     }];
}

通过UITapGestureRecognizer调用presentViewController时,从View Controller添加代码

- (void) onTapGesture:(UITapGestureRecognizer *)recognizer
{
    ImagesCollectionViewController *imagesCollectionView = [[Utils getStoryboardForDeviceWithIdentifier:MAIN_STORYBOARD] instantiateViewControllerWithIdentifier:IMAGES_VIEW];
    imagesCollectionView.transitioningDelegate = self;
    imagesCollectionView.modalTransitionStyle = UIModalPresentationCustom;

    [self presentViewController:imagesCollectionView animated:YES completion:^{

    }];
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed
{
    return self.contentSlideTransitionManager;
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source
{
    return self.contentSlideTransitionManager;
}

我猜这是您的问题:

 [container insertSubview:toVC.view belowSubview:fromVC.view];

如果toVC.view fromVC.view ,则它隐藏在它的后面,因此您看不到它的作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM