0

我只是想出如何动画插入一个 viewControll

[self transitiontoViewController:self.filterController duration:.5 options:UIViewAnimationOptionTransitionNone  animations:^{
[self.filterController.view resizeandMovewithRect:CGRectMake(0, self.filterController.view.frame.size.height, 0, 0)];
} completion:^(BOOL finished){
}];

在这里,resizeAndMovewithRect 只是使用 UIView 的这个类别来移动视图

-(void) resizeandMovewithRect:(CGRect)movement
{
    CGRect myFrame = self.frame;

    CGRect newFrame = CGRectMake(myFrame.origin.x+movement.origin.x, myFrame.origin.y + movement.origin.y, myFrame.size.width + movement.size.width , myFrame.size.height + movement.size.height);
    self.frame =newFrame;
}

现在我想做相反的事情。我希望通过将 self.filterController 移出屏幕来将其解散。

一种方法是:

[self transitiontoViewController:self.filterController duration:.5 options:UIViewAnimationOptionTransitionNone  animations:^{
[self.filterController.view resizeandMovewithRect:CGRectMake(0, -self.filterController.view.frame.size.height, 0, 0)];
} completion:^(BOOL finished){
}];

如果我这样做,则根本不会绘制动画。

在我看来,self.filterController 在动画开始时已从超级视图中删除。这就是为什么看不到 self.filterController 发生的任何事情的原因。所以我这样做

   [UIView animateWithDuration:.5 animations:^{
        [self.filterController.view resizeandMovewithRect:CGRectMake(0, -self.filterController.view.frame.size.height, 0, 0)];
    } completion:^(BOOL finished){
        [self transitiontoViewController:self.last2ViewsInTheContainer[0] duration:0 options:UIViewAnimationOptionTransitionNone  animations:^{
        } completion:nil];
    }];

所以我在调用 [self transitiontoViewController

但是,如果我这样做,那么当 self.filterController.view 被卷起时,正在替换它的视图还没有添加到 superview 中。所以那一个是看不见的。

无论如何我应该怎么做?

4

1 回答 1

0

我找到了答案。事实证明,直到最后都没有删除任何视图。问题是新的 viewController 被添加到堆栈的顶部。

所以当添加 self.filterController 时,事情就简单了。它已经在前面,而从视图在后面。

当拉出self.filterController时,那个backView在前面隐藏着self.filterController。所以解决方案是简单地将 self.filterController 读取到 superview 中,我们将看到动画。

最终代码:

[self transitiontoViewController:self.last2ViewsInTheContainer[0] duration:.5 options:UIViewAnimationOptionTransitionNone  animations:^{
    [self.filterController.view.superview addSubview:self.filterController.view]; //Put the filterControllerView at the front
    [self.filterController.view resizeandMovewithRect:CGRectMake(0, -self.filterController.view.frame.size.height, 0, 0)];
} completion:nil];
于 2012-10-30T09:26:37.243 回答