iOS 7自定义过渡:将不设置动画

iOS 7自定义过渡:将不设置动画,ios,ios7,uiviewanimation,uiviewanimationtransition,custom-transition,Ios,Ios7,Uiviewanimation,Uiviewanimationtransition,Custom Transition,我希望你能帮助我,我正在尝试在我的应用程序中实现一个自定义转换,它将显示一个自定义模式视图控制器。我能够使视图控制器按预期显示,但是,我无法使过渡设置为动画。如果您能在这方面提供任何帮助或向正确的方向提出建议,我们将不胜感激 请参阅下面我的代码: -(NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext{ return 1.0; } - (v

我希望你能帮助我,我正在尝试在我的应用程序中实现一个自定义转换,它将显示一个自定义模式视图控制器。我能够使视图控制器按预期显示,但是,我无法使过渡设置为动画。如果您能在这方面提供任何帮助或向正确的方向提出建议,我们将不胜感激

请参阅下面我的代码:

-(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];
                     }];
}
-(NSTimeInterval)transitionDuration:(id)transitionContext{
返回1.0;
}
-(void)animateTransfion:(id)transitionContext
{
UIViewController*fromVC=[transitionContext ViewControllerWorky:UITransitionContextFromViewControllerKey];
UIViewController*toVC=[transitionContext ViewControllerWorky:UITransitionContextToViewControllerKey];
CGRect sourceRect=[transitionContext initialFrameForViewController:fromVC];
fromVC.view.frame=sourceRect;
UIGraphicsBeginImageContextWithOptions(来自vc.view.frame.size,否,0);
[fromVC.view drawViewHierarchyInRect:fromVC.view.bounds AfterScreen更新:是];
UIImage*fromVCImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
UIView*容器=[transitionContext containerView];
[container setBackgroundColor:[UIColor WithPatternImage:fromVCImage];
[container insertSubview:toVC.view belowSubview:fromVC.view];
CGRect fromVCFrame=fromVC.view.frame;
__块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 WithPatternImage:fromVCImage];
[transitionContext finalFrameForViewController:toVC];
//3.执行动画。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
[UIView animateWithDuration:1.0
动画:^{
toVCFrame.origin.y=fromVCFrame.origin.y;
toVC.view.frame=toVCFrame;
[toVC.view setAlpha:1.0];
}
完成:^(布尔完成){
//动画完成后,调用completeTransition
[transitionContext completeTransition:是];
}];
}
通过UITapGestureRecognitor调用presentViewController时从视图控制器添加代码

- (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;
}
-(void)ontapsignature:(UITapGestureRecognitizer*)识别器
{
ImagesCollectionViewController*imagesCollectionView=[[Utils GetStoryboard ForDeviceWithIdentifier:MAIN\u STORYBOARD]实例化设备控制器,其标识符为:IMAGES\u VIEW];
imagesCollectionView.transitioningDelegate=self;
imagesCollectionView.modalTransitionStyle=UIModalPresentationCustom;
[自我呈现视图控制器:图像集合视图已设置动画:是完成:^{
}];
}
-(id)animationControllerForDismissedController:(UIViewController*)已解除
{
返回self.contentSlideTransitionManager;
}
-(id)animationControllerForPresentedController:(UIViewController*)PresentedPresentingController:(UIViewController*)PresentingSourceController:(UIViewController*)源
{
返回self.contentSlideTransitionManager;
}

我猜这就是你的问题:

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

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

删除此行:
[transitionContext finalFrameForViewController:toVC]它什么也不做。或者将最终帧设置为返回值!
\u块
声明是毫无意义和错误的。摆脱它。好吧,那么-这段代码到底在运行吗?我想知道您是否正确地设置了其余的过渡内容。你能告诉我其他的方法吗?证明您正在设置
TransitionDelegate
。证明您正确地实现了
animationControllerForPresentedController:
;也许会有帮助。嗨,马特,我有块声明,因为我需要更改动画块内的帧。代码确实会运行并显示视图控制器,但不幸的是,它不会设置过渡动画。您知道动画不显示的原因吗?我添加了调用presentViewController时调用的代码。谢谢你在这方面的帮助。谢谢,迈克尔