[英]UIButton click crashes app
I have button on page 1
when i click on button i am performing some animation and navigation to new page say Page 2
. 当我单击按钮时,我在
page 1
上有按钮,我正在执行一些动画和导航到新页面,例如Page 2
。
On page 2
there is cancel button when i click on that i want to go back to my previuos page ie Page 1
but on click of cancel button my app crashes. 在
page 2
有一个“取消”按钮,当我单击该按钮时,我想回到我的上一页,即Page 1
但是在单击“取消”按钮时,我的应用程序崩溃了。
Here is my sample code on Page 1:
Name of page CRViewController 这是我在
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];
}
Code which is on Page 2:
Name of page RegistraionViewController (on Which crashes on click.) Page 2:
上的代码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];
}
Try this: 尝试这个:
- (IBAction)ClickMe:(id)sender {
RegistraionViewController *secondController = [[RegistraionViewController alloc] init];
[self.navigationController pushViewController:secondController animated:YES];
}
- (IBAction) Click:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
Edit: 编辑:
I'm sorry. 对不起。 If you want custom some UIViewController transitions animation, see below:
如果要自定义一些UIViewController过渡动画,请参见以下内容:
UIViewController transition - objective-c UIViewController过渡-Objective-C
http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/ http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
Or you can try this: 或者,您可以尝试以下操作:
- (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];
}
Your problem is lying somewhere because of the subview. 由于子视图,您的问题出在某处。 I have tried your code.
我已经尝试过您的代码。
I did the following code in my project with some animation hope it helps you. 我在项目中做了以下代码,并希望动画能对您有所帮助。
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];
In animation type you can give whichever animation you want. 在动画类型中,您可以提供所需的任何动画。
Hope that helps you. 希望对您有帮助。
* *
- (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];
}
* replace your sample code on Page 1: with the above and then check. *用上面的代码替换第1页上的示例代码,然后检查。
Hope this helps to you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.