在做动画时获取EXC_BAD_ACCESS

时间:2012-06-01 12:55:18

标签: ios exc-bad-access uiviewanimation

我正在制作动画,所以当您从第一个屏幕点击按钮MyAccount时,它会导航到帐户视图

- (void)pushToAccount
{
    AccountViewController *controller = [[AccountViewController alloc] initWithNibName:@"AccountViewController" bundle:nil];
    //[self.navigationController pushViewController:controller animated:NO];

    [UIView  beginAnimations: @"Showinfo"context: nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.view addSubview:controller.view];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];
    [UIView commitAnimations];

}

但是,每当我点击帐户视图控制器(其中包含一些按钮和图像视图)时,我的程序就会崩溃,在主类上显示EXC_BAD_ACCESS

请就此问题向我提出建议......

3 个答案:

答案 0 :(得分:1)

您的视图控制器正在尝试通过将另一个视图控制器的视图添加为当前视图的子视图来设置转换动画。这在一大堆维度上存在问题。值得注意的是,你没有对新的视图控制器本身做任何事情......如果这是一个ARC项目,它将会发布给你。

如果您只想从一个视图控制器转换到另一个视图控制器,通常应该执行标准pushViewController:animated:presentModalViewController:animated:。看起来你曾经做过前者。为什么用当前代码替换它?

如果你能告诉我们你想要做什么,为什么你没有使用标准过渡,也许我们可以帮助你。

<强>更新

如果你不喜欢默认动画,而是想要过渡一些自定义动画,你可以这样做:

CustomAnimationViewController *yourNewViewController = [[CustomAnimationViewController alloc] initWithNibName:@"CustomAnimationView" bundle:nil];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[self.navigationController pushViewController:yourNewViewController animated:NO];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

// if you're using ARC, you don't need this following release, but if you're not using ARC, remember to release it

// [yourNewViewController release];

更新2:

并且,在预测逻辑后续问题时,如何设置解除新视图控制器的动画,例如,您可以使用“完成”按钮调用如下方法:

- (IBAction)doneButton:(id)sender 
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDelay:0.375];
    [self.navigationController popViewControllerAnimated:NO];
    [UIView commitAnimations];
}

答案 1 :(得分:0)

我的猜测是你有一个UIButton会在按下时调用你的pushToAccount方法,当按下它时它找不到该方法。这可能是因为方法签名不包含对象。因此,如果您从

更改方法
- (void)pushToAccount

- (void)pushToAccount:(id)sender

它可以解决您的问题。在调用该方法之前,确保包含pushToAccount方法的对象未被释放也很重要。也许在NSLog中放置dealloc消息或断点以确保它不被调用。

答案 2 :(得分:0)

我认为使用波纹线

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.window cache:YES];

你的轰鸣声线......

[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:NO];

希望这对你有所帮助...... :) 如果需要,还可以使用动画代码....

CATransition *animation = [CATransition animation];
    [animation setDelegate:self];   
    [animation setType:kCATransitionFromBottom];
    [animation setDuration:1.0];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                                  kCAMediaTimingFunctionEaseInEaseOut]];
    [[self.window layer] addAnimation:animation forKey:kAnimationKey];

这里使用你的窗口视图,否则windows workfine .. :)