从下到上而不是从右到左关闭UIViewController

时间:2011-07-19 23:04:30

标签: iphone ios uiview uiviewcontroller objective-c-blocks

我试图从下到上解除视图控制器,而不是标准的从右到左过渡。这是可能吗?这是我到目前为止的代码:

CGRect screenRect = [[UIScreen mainScreen] applicationFrame];

CGRect endFrame = self.view.frame;
endFrame.origin.y = screenRect.origin.y - screenRect.size.height;

UIView *aView = [[self.view retain] autorelease];
[self.view.window addSubview:aView];
aView.frame = CGRectMake(0, 0, 320, 460);
[UIView animateWithDuration:0.5
                 animations:^{
                     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
                     aView.frame = endFrame;
                 }
                 completion:^(BOOL finished) {
                     [self dismissModalViewControllerAnimated:NO];
                     [aView removeFromSuperview];
                 }
 ];

这确实会导致过渡;但是之前的视图控制器直到动画之后才会出现,因为在完成之前我无法解雇...任何想法?

1 个答案:

答案 0 :(得分:2)

Aah,当你提出模仿ViewController时,它会自动隐藏后面的视图。您需要做的是不存在和删除,但添加视图控制器视图作为主视图的子视图。然后,您只需在屏幕外设置动画,然后在竞争处理程序中删除SuperSuperview。