繁体   English   中英

iOS 7自定义转换问题

[英]iOS 7 custom transition issues

我试图在iPad上实现一些自定义转换,但我遇到了一些问题。 由于在旋转设备时,x,y坐标并不总是从transitionContextcontainerView的左上角开始,我写了以下方法

- (CGRect)rectForPresentedStateStart:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIView *containerView = [transitionContext containerView];

    switch (fromViewController.interfaceOrientation)
    {
        case UIInterfaceOrientationLandscapeRight:
            return CGRectMake(0, containerView.bounds.size.height,
                              containerView.bounds.size.width, containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationLandscapeLeft:
            return CGRectMake(0, - containerView.bounds.size.height * 2 / 3,
                              containerView.bounds.size.height, containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationPortraitUpsideDown:
            return CGRectMake(- containerView.bounds.size.width * 2 / 3, 0,
                              containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
        case UIInterfaceOrientationPortrait:
            return CGRectMake(containerView.bounds.size.width, 0,
                              containerView.bounds.size.width * 2 / 3, containerView.bounds.size.height);
        default:
            return CGRectZero;
    }

}

- (CGRect)rectForPresentedStateEnd:(id<UIViewControllerContextTransitioning>)transitionContext
{
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *containerView = [transitionContext containerView];


    switch (toViewController.interfaceOrientation)
    {
        case UIInterfaceOrientationLandscapeRight:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, - containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationLandscapeLeft:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], 0, containerView.bounds.size.height * 2 / 3);
        case UIInterfaceOrientationPortraitUpsideDown:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], containerView.bounds.size.width * 2 / 3, 0);
        case UIInterfaceOrientationPortrait:
            return CGRectOffset([self rectForPresentedStateStart:transitionContext], - containerView.bounds.size.width * 2 / 3, 0);
        default:
            return CGRectZero;
    }
}

在肖像模式和颠倒一切似乎工作正常。 问题出在景观上。

  1. 当设备方向为UIInterfaceOrientationLandscapeLeft ,视图在转换开始之前消失一秒钟。

  2. 当设备方向是UIInterfaceOrientationLandscapeRight我遇到以下问题:导航栏较小,当转换结束时,如图中所示,转为正常

转换发生时导航栏出现问题

转换发生时导航栏出现问题

过渡完成后

过渡完成后

我不确定这些是来自苹果的错误还是我做错了什么,如果是,我该如何解决问题呢?

这绝对是一个苹果虫。 为了呈现动画我使用这样的东西:

if (self.presenting) {
        toViewController.view.frame = [self rectForPresentedStateStart:transitionContext];
        [transitionContext.containerView addSubview:toViewController.view];
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            fromViewController.view.frame = [self rectForDismissedState:transitionContext];
            toViewController.view.frame = [self rectForPresentedStateEnd:transitionContext];
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];    
}

如果我在animateWithDuration方法之后添加视图( [transitionContext.containerView addSubview:toViewController.view]; ),导航控制器的问题就解决了。 仍然无法弄清楚为什么。

我想,你的containerViewUIWindow 所以它的界限是独立的,所以containerView.bounds.size.height在纵向和横向上是相同的。

如果我是对的,你需要使用宽度作为高度和高度作为横向宽度

暂无
暂无

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

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