当视图显示为UIModalTransitionStyleFlipHorizo​​ntal时,动画不起作用

时间:2012-03-19 20:06:38

标签: objective-c ios animation

我尝试在视图中制作带有图像的动画,但它不起作用:我的图像位于最终位置而没有动画。

UIImage *myImg = [UIImage imageNamed : @"Img72.png"];
UIImageView *myImgView =[ [UIImageView alloc] initWithImage: myImg ];
myImgView.frame= CGRectMake(250,50,72,72);
[self.view addSubview:myImgView];

[UIView animateWithDuration:0.5
                      delay: 0.0
                    options: UIViewAnimationOptionCurveEaseInOut
                 animations:^{
                     [UIView setAnimationRepeatCount:100.0];
                     [UIView setAnimationRepeatAutoreverses:YES];
                     myImgView.frame= CGRectMake(50,250,72,72);
                 }
                 completion:NULL];
[myImgView release];

相同的动画代码在另一个视图中完美运行。我终于发现它来自我用这段代码显示视图的方式:

FlipsideViewController *controller = [[[FlipsideViewController alloc] initWithNibName:@"FlipsideViewController" bundle:nil] autorelease];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //KO
[self presentModalViewController:controller animated:YES];

问题是modalTransitionStyle。当我评论该行(使用// KO)时,它最终会起作用。我测试了其他过渡风格和所有其他过渡风格(UIModalTransitionStyleCoverVerticalUIModalTransitionStyleCrossDissolveUIModalTransitionStylePartialCurl

我制作了viewDidLoadProject(效用应用),只需在viewDidLoad方法的两个视图中添加动画代码。

问题出在哪里?这是一个苹果虫吗?如何在第二个视图中进行翻转过渡和我的动画?

以下是我的示例项目:http://dl.dropbox.com/u/9204589/testFlipAnimation.zip

1 个答案:

答案 0 :(得分:2)

当所有系统内容完成后,开始使用界面似乎更自然,didAppear必须用于此目的,我相信(是的,它有效:))

FlipsideViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)viewDidAppear:(BOOL)animated
{
    UIImage *myImg = [UIImage imageNamed : @"Img72.png"];
    UIImageView *myImgView =[ [UIImageView alloc] initWithImage: myImg ];
    myImgView.frame= CGRectMake(250,50,72,72);
    [self.view addSubview:myImgView];


    [UIView animateWithDuration:0.5
                          delay: 0.0
                        options: UIViewAnimationOptionCurveEaseInOut
                     animations:^{
                         [UIView setAnimationRepeatCount:100.0];
                         [UIView setAnimationRepeatAutoreverses:YES];
                         myImgView.frame= CGRectMake(50,250,72,72);
                     }
                     completion:NULL];
    [myImgView release];


    [super viewDidAppear:animated];
}