如何解雇转换委托的视图控制器是自我?

时间:2014-12-10 22:43:03

标签: ios transition uiviewanimation uiviewanimationtransition

我为视图控制器设置了动画过渡。我没有问题将一个呈现的视图控制器添加到我当前的视图,但我无法使用dismissViewControllerAnimated忽略所呈现的视图:完成: 此外,添加呈现的视图时,它是一个tableView,具有可选择的单元格。选择单元格后,将启动新的导航控制器并将其置于顶部。当我关闭导航控制器,返回到呈现的视图时,呈现的视图已变为全屏,而不是动画放置它的位置..

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
return 0.5f;


- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
// Grab the from and to view controllers from the context
UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

// Set our ending frame. We'll modify this later if we have to
CGRect endFrame = CGRectMake(0, 300, 320, 300);

if (self.presenting) {
    fromViewController.view.userInteractionEnabled = NO;

    [transitionContext.containerView addSubview:fromViewController.view];
    [transitionContext.containerView addSubview:toViewController.view];

    CGRect startFrame = endFrame;
    startFrame.origin.y += 220;

    toViewController.view.frame = startFrame;

    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        fromViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed;
        toViewController.view.frame = endFrame;
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
}
else {
    toViewController.view.userInteractionEnabled = YES;

    [transitionContext.containerView addSubview:toViewController.view];
    [transitionContext.containerView addSubview:fromViewController.view];

    endFrame.origin.y += 320;

    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        toViewController.view.tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
        fromViewController.view.frame = endFrame;
    } completion:^(BOOL finished) {
        [transitionContext completeTransition:YES];
    }];
}

以下是我提供的视图控制器的代码:

shadedView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        shadedView.backgroundColor = [UIColor colorWithRed:224.0/255.0 green:224.0/255.0 blue:224.0/255.0 alpha:0.7];
        [self.view addSubview:shadedView];
        dismiss = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        [dismiss addTarget:self action:@selector(removeViewController) forControlEvents:UIControlEventTouchUpInside];
        dismiss.backgroundColor = [UIColor clearColor];
        [shadedView addSubview:dismiss];


        detailTableViewController = [[DetailTableViewController alloc] initWithFlag:DETAIL andQRCode:o_qrcodeId];
        //detailTableViewController.tableView.backgroundColor = [UIColor blackColor];
        detailTableViewController.transitioningDelegate = self;
        detailTableViewController.modalPresentationStyle = UIModalPresentationCustom;
        //detailTableViewController.view.layer.cornerRadius = 12.0f;
        [self presentViewController:detailTableViewController animated:YES completion:nil];

0 个答案:

没有答案