【问题标题】:UIImage to slide downwards using animationUIImage 使用动画向下滑动
【发布时间】:2012-11-23 11:07:40
【问题描述】:

如何在ios app中实现图片下滑动画?

我用过这段代码:

    imageview.animationImages = [NSArray arrayWithObjects:
                                 [UIImage imageNamed:@"img10.png"],
                                 [UIImage imageNamed:@"img11.png"],[UIImage imageNamed:@"img12.png"],[UIImage imageNamed:@"img13.png"],nil];
    imageview.animationDuration = 10.00;  

    imageview.animationRepeatCount = 0; 

    [imageview startAnimating];

但这只是一个简单的幻灯片放映。 帮帮我。

【问题讨论】:

  • 你在视图中添加了imageview??
  • 不要使用 imageView 的内置动画,而是考虑将所有图像放在一个 scrollView 中(每个图像使用一个 imageView)并通过调用 scrollRectToVisible 使用计时器向上/向下滚动。
  • 你想要什么..slide完整的imageView或只是图像
  • 好的...只使用一个视图...在此视图中添加您的 imageView 并更改您的图像视图的 x 、 y ..
  • @Rajneesh071:我如何设置 x,y?请帮助我

标签: iphone ios xcode4


【解决方案1】:

试试这段代码..

      imageview = [[UIImageView alloc] initWithFrame:self.view.frame];
      imageview.animationImages = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"img10.png"],
                             [UIImage imageNamed:@"img11.png"],[UIImage imageNamed:@"img12.png"],[UIImage imageNamed:@"img13.png"],nil];

        imageview.animationDuration = 1.25;
        imageview.animationRepeatCount = 10;
        [imageview startAnimating];
        [self.view addSubview:animationView];
        [imageview release]; 

【讨论】:

    【解决方案2】:

    请尝试以下代码

       -(void) createNewImage {
            imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,460)];
    
            imageView.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"img10.png"],
                                     [UIImage imageNamed:@"img11.png"],
                                     [UIImage imageNamed:@"img12.png"],
                                     [UIImage imageNamed:@"img13.png"],nil];
            [imageView setAnimationRepeatCount:10];
            imageView.animationDuration =1.5;
            [imageView startAnimating]; 
            [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(setLastImage:) userInfo:nil repeats:NO];
    
         }
    
        -(void)setLastImage:(id)obj
        {
            [imageView performSelectorOnMainThread:@selector(setImage:) withObject:[UIImage imageNamed:@"img12.png"] waitUntilDone:YES];
        }
    

    【讨论】:

      【解决方案3】:

      您可以使用 imgVw.centre 更改 UIImageView 的中心,您可以使用 NSTimer 更新中心。根据屏幕改变中心,可以从
      [[UIScreen mainScreen]bounds].size.height获取屏幕高度

      theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f 
              target:self 
              selector:@selector(updateTimer:) 
              userInfo:nil 
              repeats:YES];
      
      - (void)updateTimer:(NSTimer *)theTimer {
          //update centre; 
          imgVw.centre.y += 4;
      // you can update the image also if needed use if case
      imgVw.image = image2;
      
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-04-21
        • 2013-10-31
        • 1970-01-01
        • 1970-01-01
        • 2018-10-20
        • 1970-01-01
        • 2014-04-10
        相关资源
        最近更新 更多