2012-01-13 139 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