【问题标题】:How to load more(Eg: 50) jpg images to animating quickly by using NSTimer?(Ipad)如何使用 NSTimer 加载更多(例如:50)jpg 图像以快速制作动画?(Ipad)
【发布时间】:2012-04-13 04:36:40
【问题描述】:

这是我的 NSTimer 代码

   myTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self
                                             selector: @selector(callRightRotation:) userInfo: nil repeats: YES];

-(void) callRightRotation:(NSTimer*)myTimer 
  {
       ImageView.tag =[ImageView tag]+1;

           if ([ImageView tag]==50) 
                ImageView.tag=1;

     [ImageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"kisok01%i.png",[ImageView tag]]]];

      if ([ImageView tag]==1 || [ImageView tag]==50 )
       {
             [myTimer invalidate];
              myTimer= nil;


        }

   }

ipad 中加载图像非常有效,但非常困难......这里我使用的是 ".jpg" 格式图像,一张图像至少 300kb ...

我的问题是

     1. Is it possible loading very fast and smoothly ?
     2. if its not possible is there any alternative solution?

【问题讨论】:

    标签: iphone objective-c ipad uiimageview


    【解决方案1】:

    您可以为此使用 ASIHTTPRequest 而不是 timmer,因此您的图像将在后台顺利加载。并且您可以使用相同视图的其他控件。

    导入“ASIHTTPRequest.h”

    //在方法中

    [self performSelectorInBackground:@selector(DownLoadImageInBackground:) withObject:imgUrlArr];

    -(void) DownLoadImageInBackground:(NSArray *)imgUrlArr1

    {

    NSURL * url = [Image URL];
    
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
    

    }

    -(void)requestFailed:(ASIHTTPRequest *)request

    {

    NSLog(@"URL Fail : %@",request.url);
    
    NSError *error = [request error];
    
       // you can give here alert too..
    

    }

    -(void)requestFinished:(ASIHTTPRequest *)request

    {

    NSData *responseData = [request responseData];
    UIImage *imgInBackground = [[UIImage alloc]
                         initWithData:responseData];
    [imageView setImage: imgInBackground];
    

    }

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多