动画和调整UIImageView的大小

时间:2012-01-12 21:31:39

标签: iphone ios ipad uiimageview

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

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

4 个答案:

答案 0 :(得分:5)

尝试使用块动画:

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

希望有帮助!

答案 1 :(得分:0)

试试这段代码。这对我来说很好,

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

答案 2 :(得分:0)

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

尝试将imgView.frame设置为:

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

答案 3 :(得分:-1)

//设置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;

//启动动画 [我startAnimating];

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

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

相关问题