开发者

modify the width of an imageView with animation

开发者 https://www.devze.com 2023-03-26 22:41 出处:网络
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.

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. s开发者_Python百科orry for my english I'm french :/


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!


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消