放大和缩小到UIImage

时间:2012-05-01 07:11:28

标签: iphone uiimageview

我需要根据音频文件为UIImage制作动画;当声音开始时,我需要缩放到某个点,然后应用相同的动画进行缩小。我试过应用CGAffineTransformMakeScale,但它没有制作动画。将zoomin / out应用于图像的正确方法是什么?

1 个答案:

答案 0 :(得分:4)

将图像放在UIImageView中,然后使用uiview动画,重新设置框架

示例:

首先,您照常部署图像

 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