2012-01-13 138 views
0

這裏怪異的觀點是代碼:與核心動畫

UIImageView * imgView = [[UIImageView alloc] initWithImage:image]; 



       CGRect imgFrame = imgView.frame; 
       imgFrame.size.width = originalImageSize.width; 
       imgFrame.size.height = originalImageSize.height; 
       imgFrame.origin.x = 110; 
       imgFrame.origin.y = 215; 
       imgView.frame = imgFrame; 

[UIView beginAnimations:nil context:NULL]; 
       [UIView setAnimationDuration:10]; 

       CGRect frame = imgView.frame; 
       frame.size.width = SCREEN_WIDTH_PORTRAIT; 
       [imgView setFrame:frame]; 
       [imgView setCenter:CGPointMake(SCREEN_WIDTH_PORTRAIT/2, (SCREEN_HEIGHT_PORTRAIT)/2)]; 

[fullSizeImageView setBackgroundColor:[UIColor blackColor]]; 
       [UIView commitAnimations]; 

不知道爲什麼,當動畫開始時,它被一些迄今數額距離的移動有點權。任何想法?這裏的video

+0

檢查您添加imgView到哪個視圖。我會說'imgFrame.origin.x = 110;'是導致這個問題,檢查與0.這就是我可以幫助這個數量的代碼 – 2012-01-13 08:48:40

回答

0

嘗試setCenterbeginAnimations

imgView.center = CGPointMake(SCREEN_WIDTH_PORTRAIT/2, yYouLike); 

您的代碼應該是這樣的:

UIImageView * imgView = [[UIImageView alloc] initWithImage:image]; 

       CGRect imgFrame = imgView.frame; 
       imgFrame.size.width = originalImageSize.width; 
       imgFrame.size.height = originalImageSize.height; 
       imgFrame.origin.x = 110; 
       imgFrame.origin.y = 215; 
       imgView.frame = imgFrame; 

imgView.center = CGPointMake(SCREEN_WIDTH_PORTRAIT/2, yYouLike); 

[UIView beginAnimations:nil context:NULL]; 
       [UIView setAnimationDuration:10]; 

       CGRect frame = imgView.frame; 
       frame.size.width = SCREEN_WIDTH_PORTRAIT; 
       [imgView setFrame:frame]; 
       [imgView setCenter:CGPointMake(SCREEN_WIDTH_PORTRAIT/2, (SCREEN_HEIGHT_PORTRAIT)/2)]; 

[fullSizeImageView setBackgroundColor:[UIColor blackColor]]; 
       [UIView commitAnimations]; 

然後,如果你的目標是iOS 4.0或更高版本,它是更好地使用塊基於動畫的方法,像這裏寫的: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html