使用了自定义的转场动画后,toviewcontroller的tableview的位置发生了偏移,怎么破?

我做了一个这样的转场动画,
图片描述

图片描述

图片描述
但是动画结束后,发现toviewcontroller的tableview的第一行被导航栏遮住了,这是怎么回事呢? 如果使用默认的push动画,tableview就没问题。
这该怎么破?

下面是自定义动画的代码:

-(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{
    _transitionContext = transitionContext;
    
    UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    
    UIView *containerView = [transitionContext containerView];
//    [containerView addSubview:fromVC.view];
    [containerView addSubview:toVC.view];
//    [containerView insertSubview:toVC.view belowSubview:fromVC.view];
    
    UIBezierPath *startP = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(DEVICE_WIDTH/2, DEVICE_HEIGHT/2, 0.1, 0.1)];
    
//    UIBezierPath *endP = [UIBezierPath bezierPathWithOvalInRect:toVC.view.bounds];
    CGPoint finalPoint = CGPointMake(DEVICE_WIDTH/2, DEVICE_HEIGHT/2);
    CGFloat radius = sqrt(finalPoint.x *finalPoint.x + finalPoint.y * finalPoint.y);
    UIBezierPath *endP = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(CGRectMake(DEVICE_WIDTH/2, DEVICE_HEIGHT/2, 0.1, 0.1), -radius, -radius)];
    
    
    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = endP.CGPath;
    toVC.view.layer.mask = shapeLayer;
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
    animation.fromValue = (__bridge id)startP.CGPath;
    animation.toValue = (__bridge id)endP.CGPath;
    animation.duration = [self transitionDuration:transitionContext];
    animation.delegate = self;
    [shapeLayer addAnimation:animation forKey:@"path"];
}

-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    [_transitionContext completeTransition:![_transitionContext transitionWasCancelled]];
    [_transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey].view.layer.mask = nil;
    [_transitionContext viewControllerForKey:UITransitionContextToViewControllerKey].view.layer.mask = nil;
}

下面是toviewcontroller的 cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifer = @"modifyItem";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    
    if (indexPath.row == 0) {
        UILabel *oldValueLabel = [[UILabel alloc]initWithFrame:CGRectMake(kMarginLeft, 0, kLabelWidth, DEFAULT_CELL_HEIGHT)];
        if (_valueLabelContentArr.count > 0) {
            oldValueLabel.text = _valueLabelContentArr[_index][0];
            oldValueLabel.font = DEFAULT_FONT(14);
        }
        [cell.contentView addSubview:oldValueLabel];
    }

    
    return cell;
}
阅读 5.9k
5 个回答

self.automaticallyAdjustsScrollViewInsets = YES;

更改这个UIViewController的属性试试,不行的话就直接改contentInset

给你的tableView的content加一个上边距就行了,

tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);

碰到了和楼主一样的问题, iOS8上正常,iOS9上就出现了这个问题, 最奇葩的是当挂到后台然后再打开时又恢复正常了,我都怀疑是不是iOS9的bug
楼主解决没.

打印那个toViewController的frame,size是不是600*600,我上次好像就是这样子,重新设定他的frame为当前屏幕的尺寸就行了

新手上路,请多包涵

楼主有没有解决这个问题,好像是自定义转场动画会使得self.edgesForExtendedLayout = UIRectEdgeNone失效,但使用系统的就不会。我的项目都使用了UIRectEdgeNone,想要加转场动画找不到解决方案啊。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题