0

我正在制作动画,因此当您从第一个屏幕单击 MyAccount 按钮时,它会将您导航到 Account View

- (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

请就这个问题给我建议...

4

3 回答 3

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];
}
于 2012-06-01T14:42:46.367 回答
0

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

- (void)pushToAccount

- (void)pushToAccount:(id)sender

它可能会解决您的问题。确保包含该pushToAccount方法的对象在调用该方法之前没有被释放也很重要。也许NSLog在里面放一条消息或断点dealloc以确保它不被调用。

于 2012-06-01T13:05:34.500 回答
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];

在这里使用您的窗口视图,否则窗口工作正常.. :)

于 2012-06-01T13:15:10.793 回答