【问题标题】:animate and resize UIImageView动画和调整 UIImageView
【发布时间】:2012-02-09 04:29:45
【问题描述】:

如何为 UIImageView 设置动画并调整其大小?我试过这样做,但对我来说没有用:

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

【问题讨论】:

  • 发生了什么? imgView 的起始帧是什么?你在哪里表演这个?我们需要更多信息。

标签: iphone ios ipad uiimageview


【解决方案1】:

尝试使用块动画:

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

希望有帮助!

【讨论】:

    【解决方案2】:

    //设置UIImageView。 Frame 确定图像的位置和大小。 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.frame = CGRectMake(x, y, width, height);

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

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

        尝试将 imgView.frame 设置为:

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

        【讨论】:

          猜你喜欢
          • 2010-12-27
          • 2019-10-28
          • 1970-01-01
          • 2018-06-16
          • 1970-01-01
          • 1970-01-01
          • 2023-03-30
          相关资源
          最近更新 更多