TableView分割动画segue

时间:2013-08-29 15:18:46

标签: ios objective-c core-animation uistoryboardsegue

我正在研究一个应该像这样工作的自定义动画segue:

User taps cell in table view,
table view splits underneath the selected cell,
bottom half translates down, upper half translates up to reveal destination view

不幸的是,我一直无法将视图分成两部分。我的想法是创建视图的两个快照,然后改变这些快照的边界,一个代表底部,一个代表顶部,隐藏下面的视图,然后翻译快照。

但是,有两个问题:1)如果源视图隐藏或更改alpha,快照也会更改(因为拍摄快照的唯一方法是使它们成为源视图的子视图)。 2)目标视图在黑屏后显示较晚。

关于问题是什么的任何想法?或许是一个新的方向来接受它?

下面是代码:

@interface ExpandTableViewSegue()

// there are these also in header
// UIImageView *topView;
// UIImageView *bottomView;

@property (strong, nonatomic) UIView *containerView;
@property (strong, nonatomic) UIViewController *imageContainerViewController;

@property (strong, nonatomic) UIView *backgroundView;

@property (strong, nonatomic) UINavigationController *navigationController;

@end

@implementation ExpandTableViewSegue


- (void)perform {
    self.navigationController = [self.sourceViewController navigationController];

    [self pushDestinationControllerToNavigationStack];
    self.backgroundView = [[self.destinationViewController view] snapshotView];
    [self popTopMostControllerOffStack];

    [self pushImageContainerControllerToNavigationStack];
    [self animateImagesInContainerView];
}

- (void)pushDestinationControllerToNavigationStack {
    [self.navigationController pushViewController:self.destinationViewController animated:NO];
}

- (void)pushImageContainerControllerToNavigationStack {
    UIViewController *imageContainerController = [self imageContainerViewController];

    [self.navigationController pushViewController:imageContainerController animated:NO];
}

- (void)animateImagesInContainerView {
    [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{

        [[self.sourceViewController view]removeFromSuperview];
        [self translateTopImageUp];
        [self translateBottomImageDown];
        [self.containerView removeFromSuperview];
    }
    completion:^(BOOL finished) {
        if (finished) {
            [self popTopMostControllerOffStack];
            [self pushDestinationControllerToNavigationStack];
        }
    }];
}

EDIT1 :(更新的代码)我解决了第一个问题......我所做的是创建一个容器视图,其中包含两个快照图像,然后在执行动画之前将该视图推送到导航堆栈。 但我仍然遇到第二个问题,它处理目标控制器被推入堆栈的时间。我想要的是动画逐渐显示下面的目标视图。但是现在它显示黑屏(当前视图),然后弹出到目标视图。

我尝试的解决方案是快速将目标视图推送到堆栈,拍摄快照,然后将其从堆栈中弹出。 然后继续执行该过程,但将新快照添加到后台,以便它显示在前两个快照的后面。

有什么新想法吗?谢谢!

1 个答案:

答案 0 :(得分:0)

你有一个很好的方法。我会拍摄快照,然后将它们传递给-prepareForSegue:方法中的destinationViewController。让destinationViewController处理它们,并在动画完成后删除它们。 或者,如果已经将图像子类化,则可以将图像传递给segue。