2012-03-19 83 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