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

使用了自定义的转场动画后,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;
}

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

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

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


self.automaticallyAdjustsScrollViewInsets = YES;

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

【热门文章】
【热门文章】