-1

我有一个 imageView 作为应用程序的背景。我在背景顶部有一个按钮。我想按下该按钮并放大背景图像的动画。解决此问题的最佳方法是什么?我应该使用滚动视图吗?

4

3 回答 3

3

我认为在动画块中使用变换是最好的方法。你可以这样做:

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

并将其放回初始位置,您只需执行以下操作:

[UIView animateWithDuration:0.3 animations:^
{
    [yourImageView setTransform:CGAffineTransformIdentity];
}];
于 2013-05-07T23:01:46.343 回答
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];
}
于 2013-05-07T21:22:21.170 回答
0
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)
        })
    }
}
于 2018-09-26T13:44:25.920 回答