2012-05-01 211 views
2

我需要根據音頻文件爲UIImage製作動畫;當聲音開始時,我需要對某個點進行縮放,然後應用相同的動畫進行縮小。我試圖應用CGAffineTransformMakeScale,但它不製作動畫。將縮放/縮小應用於圖像的正確方法是什麼?放大和縮小爲UIImage

回答

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]; 

或者您可以使用該方法動畫(這是多一點點的進步,但更好的我認爲)

//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