目前模态视图与动画效果

时间:2012-05-22 10:06:50

标签: iphone objective-c ios animation

在我的iPhone应用程序中,我需要显示一个透明背景的模态视图,它应该显示动画,就像它从视图中心出现并且它的大小正在增加。

当我们点击设置按钮时,类似于“画画”iPhone App。

我该怎么做?

3 个答案:

答案 0 :(得分:3)

您可以执行以下4种转换样式之一:

viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
viewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;

[self presentModalViewController:viewController animated:YES];

如果你想要一些不包含在这些默认值中的东西,你将不得不构建自己的自定义动画来呈现模态视图。如下所示,但显然是你想要的风格。

UIModalTransitionStyle horizontal movement

答案 1 :(得分:3)

假设您有一个viewController,它调用了您想要呈现的aScoreSheet。尝试在将要进行演示的视图控制器中定义此方法。

-(void) presentTransparentModalViewController: (ScoreSheet *) aViewController 
{

    scoreSheet = aViewController;
    UIView *view = aViewController.view;

view.opaque = NO;
[view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    UIView *each = obj;
    each.opaque = NO;
}];
    [self.view addSubview:view];

    view.center = CGPointMake(160, 800); //for iPhone

    [UIView animateWithDuration:0.9 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
         view.center = CGPointMake(160, 240);
    } completion:^(BOOL finished) {

        self.view.userInteractionEnabled=YES;
    }];

}

然后解雇控制器:

-(void) dismissTransparentModalViewControllerAnimated:(BOOL) animated{

if (animated) {

    [UIView animateWithDuration:0.4
                     animations:^{
                         scoreSheet.view.center = CGPointMake(scoreSheet.view.center.x, scoreSheet.view.center.y + 480);
                     } completion:^(BOOL finished) {
                         [scoreSheet.view removeFromSuperview];
                         scoreSheet = nil;
                     }];
}


}

答案 2 :(得分:0)

不是完整的答案,但也许你可以看看这个开源库:

https://github.com/Split82/HMGLTransitions

它有一些自定义模态转换,可能不是您正在寻找的转换,但您可以通过子类HMGLTransition轻松添加转换。

希望这有帮助