【问题标题】:iOS 7 custom transition issuesiOS 7 自定义过渡问题
【发布时间】:2014-09-08 02:51:03
【问题描述】:

我正在尝试在 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 时,出现以下问题:导航栏变小,当过渡结束时变为正常状态,如图所示

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

过渡完成后

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

【问题讨论】:

  • @Spynet 我尝试在表格视图中更改它,但不幸的是没有任何更改
  • 看起来还是一样或有一些额外的行为......
  • @Spynet 看起来完全一样。当我使用自动布局时它看起来也一样
  • 你能多解释一下你有2张桌子还是1张桌子和

标签: ios uiviewanimationtransition


【解决方案1】:

我猜,你的containerViewUIWindow。所以它的边界与方向无关,所以containerView.bounds.size.height 在纵向和横向上是相同的。

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

【讨论】:

  • 不完全是。它不像 UIWindow。旋转时,轴不会停留在左上角。所以一切都应该做相应的调整。
【解决方案2】:

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

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];
        }];    
}

如果我添加视图,导航控制器的问题就解决了([transitionContext.containerView addSubview:toViewController.view]; ) 在animateWithDuration 方法之后。还是不知道为什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多