繁体   English   中英

动画和调整UIImageView的大小

[英]animate and resize UIImageView

如何动画和调整UIImageView的大小? 我试过这样做,但对我来说没有用:

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

尝试使用块动画:

[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){
                 }];

希望有帮助!

试试这个代码。 这对我很好,

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

如果我们假设您对imgView有正确的引用,那么似乎imgView的起始帧在动画之前和之后是相同的。

尝试将imgView.frame设置为:

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

//设置UIImageView。 框架确定图像的位置和大小。 UIImageView * i = [[UIImageView alloc] initWithFrame:[CGRectMake(50.0,50.0,50.0,50.0)]];

//将图像添加到UIImageView i.images = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@“1.png”],
[UIImage imageNamed:@“2.png”],nil];

//设置动画运行的时间i.animationDuration = 1.0f;

//启动动画[i startAnimating];

您可以通过更改图像的帧来调整图像大小

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

暂无
暂无

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

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