0

page 1当我单击按钮时,我有按钮,我正在执行一些动画和导航到新页面说Page 2

page 2我点击我想回到我的previuos页面时Page 1有取消按钮,但点击取消按钮我的应用程序崩溃。

这是我在Page 1:页面名称 CRViewController上的示例代码

- (IBAction)ClickMe:(id)sender {
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromBottom];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom];
    [self.view addSubview:secondController.view];
}

Page 2: 页面名称RegistraionViewController上的代码(点击时崩溃。)

- (IBAction)Click:(id)sender {
    CRViewController *secondController = [[CRViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromTop];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom];
    [self.view addSubview:secondController.view];
}
4

3 回答 3

1

尝试这个:

- (IBAction)ClickMe:(id)sender {   
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];   
    [self.navigationController pushViewController:secondController animated:YES];   
}


- (IBAction) Click:(id)sender {    
   [self.navigationController popViewControllerAnimated:YES];    
}

编辑:
对不起。如果你想自定义一些 UIViewController 过渡动画,见下文:
UIViewController 过渡 - Objective-c
http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
或者你可以试试这个:

- (IBAction)ClickMe:(id)sender {
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromBottom];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.navigationController.view.layer addAnimation:transitionAnimation forKey:nil];
    [self.navigationController pushViewController:secondController animated:NO]; 
}

- (IBAction)Click:(id)sender {
    CRViewController *secondController = [[CRViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromTop];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.navigationController.view.layer addAnimation:transitionAnimation forKey:nil];
    [self.navigationController popToViewController:secondController animated:NO];
}
于 2013-10-30T09:55:10.113 回答
0

由于子视图,您的问题出在某个地方。我试过你的代码。

我在我的项目中使用了一些动画制作了以下代码,希望对您有所帮助。

CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
    [animation setDuration:0.8];
    [animation setType:kCATransitionFade];
    [animation setSubtype:kCATransitionMoveIn];

    //[[self.view layer]addAnimation:animation forKey:@"fview"];

    [self.navigationController.view.layer addAnimation:animation forKey:nil];

    [self.navigationController pushViewController:yourView animated:NO];

在动画类型中,您可以提供您想要的任何动画。

希望对您有所帮助。

于 2013-10-30T10:09:13.177 回答
0

*

- (IBAction)ClickMe:(id)sender {
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];
    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromBottom];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom];
    [self addChildViewController:secondController];
    [self.view addSubview:secondController.view];
}

* 将第 1 页上的示例代码替换为上述内容,然后检查。

希望这对你有帮助

于 2013-10-30T11:26:27.230 回答