2013-05-07 82 views
-1

我有一個imageView作爲應用程序的背景。我在背景上有一個按鈕。我想按下該按鈕並放大背景圖像的動畫。解決此問題的最佳方法是什麼?我應該使用scrollview嗎?iOS:使用按鈕縮放圖像

回答

3

我認爲在動畫塊中使用變換是最好的方法。 你可以做這樣的事情:

[UIView animateWithDuration:0.3 animations:^ 
{ 
    [yourImageView setTransform:CGAffineTransformMakeScale(1.5, 1.5)]; 
}]; 

,並把它放回到初始位置,你只需要做到這一點:

[UIView animateWithDuration:0.3 animations:^ 
{ 
    [yourImageView setTransform:CGAffineTransformIdentity]; 
}]; 
2

是這樣的嗎?

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
myButton.frame = CGRectMake(80, 50, 150, 40); 
[myButton setTitle:@"Your button!" forState:UIControlStateNormal]; 
[myButton setBackgroundImage:[UIImage imageNamed:@"xyz.png"]];  
[self.view addSubview:myButton]; 

-(IBAction)buttonClicked:(UIButton *)sender 
{ 
    self.frame = CGRectMake(0.0f, 0.0f, 200.0f, 150.0f); 
    [UIView beginAnimations:@"Zoom" context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    self.frame = CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f); 
    [UIView commitAnimations]; 
} 
+1

不要啓動的操作方法的動畫,它會與按鈕動畫相撞。將它發佈到塊中的主隊列中,它看起來會更好。雖然很好的答案! – 2013-05-07 21:51:58