使用动画修改 imageView 的宽度

发布于 2024-11-29 03:07:16 字数 89 浏览 1 评论 0原文

我有一个图像“image1”,它是一个 UIButton,我想要的是,如果我触摸这个按钮,图像的宽度乘以二(带动画)而不是高度只是宽度。 抱歉我的英语我是法国人:/

I have an image "image1" which is a UIButton and what I want is that if I touch this button, the width of the image is multiplied by two (with animation)not the height just the width.
sorry for my english I'm french :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为人所爱 2024-12-06 03:07:16

对于块动画来说这相当容易。只需尝试一下:

imageView.contentMode = UIViewContentModeScaleAspectFit;

[UIView animateWithDuration:1.0
                       animations:^{ 
                         CGRect newRect = imageView.frame;
                         int movementToTheLeft = imageView.frame.size.width / 2;
                         newRect.size.width *= 2;
                         newRect.origin.x -= movementToTheLeft;
                         imageView.frame = newRect;
                       }
                       completion:^(BOOL finished){

                         [UIView animateWithDuration:1.0
                                          animations:^{ 
                                            NSLog(@"Scaled!");// Anything can go in  this completion block, it should be used for any logic you need after the animation.
                                          } 
                                          completion:^(BOOL finished){
                                            ;
                                          }];

这应该会将 imageView 的宽度缩放 2 倍。希望有帮助!

This is fairly easy with block animation. Simply try:

imageView.contentMode = UIViewContentModeScaleAspectFit;

[UIView animateWithDuration:1.0
                       animations:^{ 
                         CGRect newRect = imageView.frame;
                         int movementToTheLeft = imageView.frame.size.width / 2;
                         newRect.size.width *= 2;
                         newRect.origin.x -= movementToTheLeft;
                         imageView.frame = newRect;
                       }
                       completion:^(BOOL finished){

                         [UIView animateWithDuration:1.0
                                          animations:^{ 
                                            NSLog(@"Scaled!");// Anything can go in  this completion block, it should be used for any logic you need after the animation.
                                          } 
                                          completion:^(BOOL finished){
                                            ;
                                          }];

This should scale your imageView's width by 2. Hope that helps!

笑红尘 2024-12-06 03:07:16

老式的方式(iOS 4.0之后不推荐,但仍然有效):

[UIView beginAnimations:@"widen" context:nil];
[UIView setAnimationDuration:1.0];
CGRect newRect = imageView.frame;
newRect.width *= 2;
imageView.frame = newRect;
 // ... set more parameters if desired
[UIView commitAnimations];

The old fashioned way (not recommended after iOS 4.0, but still works):

[UIView beginAnimations:@"widen" context:nil];
[UIView setAnimationDuration:1.0];
CGRect newRect = imageView.frame;
newRect.width *= 2;
imageView.frame = newRect;
 // ... set more parameters if desired
[UIView commitAnimations];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文