Iphone 如何使用NSTimer(Ipad)快速加载更多(例如:50)jpg图像以制作动画
这是我的NSTimer代码Iphone 如何使用NSTimer(Ipad)快速加载更多(例如:50)jpg图像以制作动画,iphone,objective-c,ipad,uiimageview,Iphone,Objective C,Ipad,Uiimageview,这是我的NSTimer代码 myTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(callRightRotation:) userInfo: nil repeats: YES]; -(void) callRightRotation:(NSTimer*)myTimer {
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
我的问题是
为此,您可以使用AsiTRequest而不是timmer,这样您的图像将在背景中顺利加载。您可以使用同一视图的其他控件 导入“ASIHTTPRequest.h” //以某种方式 [self-performSelectorInBackground:@selector(DownLoadImageInBackground:)with object:imgurlar] -(无效)下载ImageInBackground:(NSArray*)imgurlar1 { } -(void)requestFailed:(ASIHTTPRequest*)请求 { } -(void)requestFinished:(ASIHTTPRequest*)请求 {
}感谢您的重播!!!但我的问题是我想在nstimer中使用下面的代码
1. Is it possible loading very fast and smoothly ?
2. if its not possible is there any alternative solution?
NSURL * url = [Image URL];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
NSLog(@"URL Fail : %@",request.url);
NSError *error = [request error];
// you can give here alert too..
NSData *responseData = [request responseData];
UIImage *imgInBackground = [[UIImage alloc]
initWithData:responseData];
[imageView setImage: imgInBackground];