0

这是我的 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?
4

1 回答 1

0

您可以为此使用 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];

}

于 2012-04-13T04:55:21.723 回答