2012-03-19 58 views
1

我尝试在视图中制作带有图像的动画,但无法正常工作:我的图像位于没有动画的最终位置。当视图呈现UIModalTransitionStyleFlipHorizo​​ntal时,动画无法正常工作

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。当我评论该行(与/ /),它终于有效。我测试的其他过渡的风格和所有的其他作品(UIModalTransitionStyleCoverVerticalUIModalTransitionStyleCrossDissolveUIModalTransitionStylePartialCurl

我做了一个viewDidLoadProject(实用应用程序),只是添加了动画代码在这两个视图中viewDidLoad方法。

问题在哪里?这是一个苹果的错误?我怎样才能有一个翻转过渡,我的动画在第二个视图中工作?

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

回答

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]; 
} 
+0

YEEEEESSSSSS,感谢您的快速和完美的答案:-)它是如此简单。正如我们在法国所说的那样,“J'avais latêtedans le guidon”。 – Alex 2012-03-19 23:12:59

+0

BULLS眼睛!就是我想要的 – Siddharthan 2012-08-22 13:17:59