2012-01-12 206 views
3

如何動畫和調整UIImageView的大小?我試着這樣做,並沒有爲我工作了:動畫和調整大小UIImageView

[UIView beginAnimations:nil context:NULL]; 
      [UIView setAnimationDuration:1.0]; 
      imgView.frame = CGRectMake(0, 0, 320, 480); 
      [UIView commitAnimations]; 
+0

沒有發生什麼? 'imgView'的開始幀是什麼?你在哪裏表演?我們需要更多信息。 – 2012-01-12 21:33:04

回答

5

嘗試使用塊動畫:

[UIView animateWithDuration:1.0f // This can be changed. 
       animations:^{ 
        CGRect frame = imageView.frame; 
        frame.size.width += 100.0f; // This is just for the width, but you can change the origin and the height as well. 
        imageView.frame = frame; 
       } 
       completion:^(BOOL finished){ 
       }]; 

希望幫助!

-1

//設置UIImageView。該框架確定圖像的位置和大小。 UIImageView * i = [[UIImageView alloc] initWithFrame:[CGRectMake(50.0,50.0,50.0,50.0)]];

//添加圖像的UIImageView i.images = [[NSArray中的alloc] initWithObjects:[UIImage的imageNamed:@ 「1.png」],
[UIImage的imageNamed:@ 「2.png」],零] ;

//設置動畫運行的時間量 i.animationDuration = 1.0f;

//開始動畫 [i startAnimating];

可以通過改變圖像

i.frame = CGRectMake(X,Y,寬度,高度)的框架調整圖像的大小;

0

試試看看這個代碼。這對我來說工作得很好,

 CGPoint newLogoutCenter = CGPointMake(160, 364); 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0f]; 
    twitterBarVIew.center = newLogoutCenter; 
    [UIView commitAnimations]; 
0

如果我們假設你有正確的參考imgView,那麼它似乎開始imgView的幀之前和之後的動畫相同。

嘗試imgView.frame設置爲:

imgView.frame = CGRectMake(100,100,100,100);