简体   繁体   English

动画和调整UIImageView的大小

[英]animate and resize UIImageView

How do I animate and resize a UIImageView? 如何动画和调整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. 如果我们假设您对imgView有正确的引用,那么似乎imgView的起始帧在动画之前和之后是相同的。

Try to set imgView.frame to: 尝试将imgView.frame设置为:

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

//Set up the UIImageView. //设置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)]]; 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"], //将图像添加到UIImageView i.images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@“1.png”],
[UIImage imageNamed:@"2.png"], nil]; [UIImage imageNamed:@“2.png”],nil];

//Set the amount of time for the animation to run i.animationDuration = 1.0f; //设置动画运行的时间i.animationDuration = 1.0f;

//start the animations [i startAnimating]; //启动动画[i startAnimating];

You can resize the image by changing the frame of the image 您可以通过更改图像的帧来调整图像大小

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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