我需要根据音频文件为 UIImage 制作动画;当声音开始时,我需要缩放到某个点,然后应用相同的动画进行缩小。我试图应用 CGAffineTransformMakeScale 但它不会制作动画。将放大/缩小应用到图像的正确方法是什么?
问问题
1272 次
1 回答
4
把图片放到一个UIImageView中,然后用uiview动画,重新设置frame
例子 :
首先,您像往常一样部署映像
UIImage *myImg = [UIImage imageNamed:@"myImage.png"];
UIImageView *myImgView = [[UIImageView alloc]initWithImage:myImg];
[myImgView setFrame:CGRectMake(10, 10, 100, 100)];
[self.view addSubview:myImgView];
然后你实现动画代码使视图更大
//START THE ANIMATION
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[myImgView setFrame:CGRectMake(10, 10, 300, 300)]; //re-set your image view size so that it become bigger
[UIView commitAnimations];
或者你可以使用方法 animate (这有点先进,但我认为更好)
//START THE ANIMATION
[UIView animateWithDuration:1.0 animations:^
{
[myImgView setFrame:CGRectMake(10, 10, 300, 300)]; //re-set your image view size so that it become bigger
} completion:^(BOOL finished)
{
//type here what you want your program to do after the animation finished
}];
祝你好运:D
于 2012-05-01T07:21:35.087 回答