iOS:视图控制器之间的动画

时间:2013-07-04 23:10:08

标签: ios animation uiview uiviewcontroller segue

我无处可寻。所以,如果你掌握了相关信息,请给我一个链接。

我有一个视图控制器,我为一个简单的游戏制作了一个菜单。它上面有一些按钮。 我有另一个视图控制器,还有一些按钮。

问题是: “在我选择一个触发自定义segue(没有任何动画)的按钮到另一个视图控制器之后,我怎么能做这个按钮的动画(隐藏在屏幕上),这个按钮会运行它的按钮动画(从边框进入屏幕)屏幕)?“

我是这样做的:

1)理论:我为菜单按钮做了一个IBAction,然后在这个IBAction中我调用一个动画方法,它调用performSegueMethod:。在此之后,在新的VC中,在viewWillAppear方法中调用一个动画方法(这种方法与源VC几乎相同)。这一切都有效,但这看起来并不顺利。当目标VC替换源VC时,会出现此动画的问题。当所有看起来都是静态的时候,并且只有在这个动画开始之后才有一些瞬间。 我不知道如何删除此目标VC滞后。可能是我必须在segue之前加载目的地视图?我试图这样做,但可能是一个错误的,或者它只是没有帮助我。

2)练习:

firstViewController.m:

- (IBAction)newGameSegueButton {

[self menuSlideInDirection:@"CenterToLeft" performingSegueWithIdentifier:@"mode"];

}


-(void)menuSlideInDirection:(NSString *)direction performingSegueWithIdentifier:(NSString *)segueIdentifier
{


[UIView animateWithDuration:0.4 animations:^{

    CGPoint newGameButtonCenter;
    newGameButtonCenter.x = directionIndex * 160;
    newGameButtonCenter.y = self.gameButtonSlide.center.y;
    self.gameButtonSlide.center = newGameButtonCenter;

    [UIView animateWithDuration:0.3 delay:0.1 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
       //some animation too

    } completion:nil];


    [UIView animateWithDuration:0.2 delay:0.2 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
        //animation 

    } completion:nil];


    [UIView animateWithDuration:0.1 delay:0.3 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
       //some animation too

    } completion:^(BOOL finished){

        if(segueIdentifier){
            [self performSegueWithIdentifier:segueIdentifier sender:self];

        }
    }];





}];


}

好的,然后自定义segue代码非常简单:

-(void)perform
{


UIViewController *src = self.sourceViewController;
UIViewController *dst = self.destinationViewController;

[src.navigationController pushViewController:dst animated:NO];


}

我的secondViewController.m:

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];


[self menuSlideInDirection:@"RightToCenter" performingSegueWithIdentifier:nil];

}

menuSlideInDirection:@“RightToCenter”performSegueWithIdentifier:secondViewController中的nil与firstView中具有相同名称的方法相同。

我正在寻找在segue之后的目标视图控制器的特定对象的平滑动画。

可能是做错了,有另一种方法可以做到这一点吗? (我只考虑将目标VC的所有视图和所有控件添加到源VC并删除“目标VC”。

希望,有人可以帮助我。

2 个答案:

答案 0 :(得分:0)

尝试使用perform方法完成所有第一个视图控制器的动画。

对于第二个视图控制器的动画,我不认为还有其他好的'比在viewWillAppear中做的方式(虽然我更喜欢viewDidAppear),因为在执行segue时没有设置目标视图控制器的出口(它们将是零)。换句话说,您无法访问按钮,更不用说为它们设置动画了。

一种hackish方式是在[segue.destinationViewController view]之前调用perform,以便加载目标视图控制器的视图层次结构并设置出口。那么也许,您可以在perform中的目标视图控制器中设置按钮,然后将其推入导航堆栈。

答案 1 :(得分:0)

对于我的问题,我选择在同一个VC下放置两个视图的方式。动画很流畅,看起来比使用perform / viewWillAppear方法要好得多。