iOS:使用按钮缩放图像
问题描述:
我有一个imageView作为应用程序的背景。我在背景上有一个按钮。我想按下该按钮并放大背景图像的动画。解决此问题的最佳方法是什么?我应该使用scrollview吗?iOS:使用按钮缩放图像
答
我认为在动画块中使用变换是最好的方法。 你可以做这样的事情:
[UIView animateWithDuration:0.3 animations:^
{
[yourImageView setTransform:CGAffineTransformMakeScale(1.5, 1.5)];
}];
,并把它放回到初始位置,你只需要做到这一点:
[UIView animateWithDuration:0.3 animations:^
{
[yourImageView setTransform:CGAffineTransformIdentity];
}];
答
是这样的吗?
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];
}
不要启动的操作方法的动画,它会与按钮动画相撞。将它发布到块中的主队列中,它看起来会更好。虽然很好的答案! – 2013-05-07 21:51:58