我使用以下方法切换视图:
FirstView.m
-(IBAction)showAnimal:(UIButton *)sender{
NSString *digit = [NSString stringWithFormat:@"%d",[sender tag]];
//NSString *digit = [[sender titleLabel] text];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.indexOfImage = digit;
Animal *myAnimal = [[Animal alloc]
initWithNibName:@"Animal" bundle:nil];
[UIView beginAnimations:@"flipView" context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view cache:YES];
[UIView commitAnimations];
//[self presentModalViewController:myAnimal animated:YES];
myAnimal.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:myAnimal.view];
self.view.bounds = myAnimal.view.bounds;
}
第二视图的方法 的 Animal.m
-(IBAction)backToFront:(id)sender{
[UIView beginAnimations:@"flipView" context:nil];
[UIView setAnimationDuration:1.2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view.superview cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}
我多次使用此代码,它一直没有任何问题,直到现在。 每当我想切换回来时,我的应用程序都会破碎。因此 Animal 视图上的方法崩溃了。奇怪的是我得到了一个奇怪的错误。我得到了截图。
请帮忙!
答案 0 :(得分:1)
EXC_BAD_ACCESS通常在您处理发布对象(Zombies)时出现..转到产品>编辑方案>在环境变量区域添加值为yes的NSZombieEnabled。这将在控制台中显示僵尸对象。
答案 1 :(得分:1)
我认为这里发生的事情是你在动画完成之前从超级视图中删除视图。如果您的视图控制器没有保留已删除的视图,它将被释放,并且可能会在删除后立即释放。动画将导致您获得的错误访问异常,因为它正在尝试访问不再存在的对象。
要修复,请避免在动画完成之前从超级视图中删除视图。
答案 2 :(得分:0)
感谢您的帮助,但我找到了另一种处理该错误的方法。你是对的。之前的观点在回到他之前被解除了分配。这是由于ARC(自动引用计数)所以我使用this article将其关闭。所以我会给你们两个积分来帮助我!我很感激!