UIButton点击崩溃的应用程序

时间:2013-10-30 09:47:27

标签: ios iphone ipad uibutton catransition

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

page 2上点击取消按钮我想回到我的上传页面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];
}

3 个答案:

答案 0 :(得分: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 transition - 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];
}

答案 1 :(得分: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];

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

希望对你有所帮助。

答案 2 :(得分: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页上的示例代码:使用上面的内容然后检查。

希望这对你有帮助