【发布时间】:2013-05-07 21:17:49
【问题描述】:
我有一个 imageView 作为应用程序的背景。我在背景顶部有一个按钮。我想按下该按钮并放大背景图像的动画。解决此问题的最佳方法是什么?我应该使用滚动视图吗?
【问题讨论】:
标签: ios xcode zooming scrollview
我有一个 imageView 作为应用程序的背景。我在背景顶部有一个按钮。我想按下该按钮并放大背景图像的动画。解决此问题的最佳方法是什么?我应该使用滚动视图吗?
【问题讨论】:
标签: ios xcode zooming scrollview
我认为在动画块中使用变换是最好的方法。 你可以这样做:
[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];
}
【讨论】:
swift 4
func zoomOut(){
DispatchQueue.main.async{[weak self] in
UIView.animate(withDuration: 0.3, animations: {[weak self] in
self?.imageView.transform = .identity
})
}
}
func zoomIn(){
DispatchQueue.main.async{[weak self] in
UIView.animate(withDuration: 0.3, animations: {[weak self] in
self?.imageView.transform = CGAffineTransform(scaleX: 1.3, y: 1.3)
})
}
}
【讨论】: