简体   繁体   中英

animate and resize UIImageView

How do I animate and resize a UIImageView? I tried doing this and it didn't work out for me:

[UIView beginAnimations:nil context:NULL];
            [UIView setAnimationDuration:1.0];
            imgView.frame = CGRectMake(0, 0, 320, 480);
            [UIView commitAnimations];

Try using a block animation:

[UIView animateWithDuration:1.0f // This can be changed.
                 animations:^{
                   CGRect frame = imageView.frame;
                   frame.size.width += 100.0f; // This is just for the width, but you can change the origin and the height as well.
                   imageView.frame = frame;
                 } 
                 completion:^(BOOL finished){
                 }];

Hope that Helps!

Try this code. This works fine for me,

        CGPoint newLogoutCenter = CGPointMake(160, 364);
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:1.0f];
    twitterBarVIew.center = newLogoutCenter;
    [UIView commitAnimations];

If we assume that you have correct reference to the imgView, then it seems that starting frame of the imgView is the same before and after animation.

Try to set imgView.frame to:

imgView.frame = CGRectMake(100,100,100,100);

//Set up the UIImageView. the Frame determines the position and size of the image. UIImageView *i = [[UIImageView alloc] initWithFrame:[CGRectMake(50.0,50.0,50.0,50.0)]];

//Add images to UIImageView i.images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"], nil];

//Set the amount of time for the animation to run i.animationDuration = 1.0f;

//start the animations [i startAnimating];

You can resize the image by changing the frame of the image

i.frame = CGRectMake(x, y, width, height);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM