scrollView에 imageView가 포함되어 있습니다. imageView는 인터넷에서 (flickr API를 통해) 다운로드해야하므로이 문제를 처리 할 수있는 스레드를 추가해야합니다. 그러나 이미지 다운로드가 끝나면 어떻게해야합니까? 이미지 뷰를 다시로드하려면 어떻게해야합니까? 여기에 제 코드가 있습니다.iOS에서 내보기를 다시로드하는 방법
실제로 작동 중입니다. 하지만 imageView의 크기는 (0, 0)입니다. 어떻게 해결할 수 있습니까?
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.myImage)
{
UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[spinner startAnimating];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:spinner];
dispatch_queue_t downloadQueue = dispatch_queue_create("flickr downloader (photo)", NULL);
dispatch_async(downloadQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:[FlickrFetcher urlForPhoto:self.photo format:FlickrPhotoFormatLarge]];
dispatch_async(dispatch_get_main_queue(), ^{
self.myImage = [UIImage imageWithData:data];
[self.imageView setImage:self.myImage];
[self viewDidLoad];
[self viewWillAppear:NO];
NSLog(@"imageViewSet!");
self.navigationItem.rightBarButtonItem = nil;
});
});
dispatch_release(downloadQueue);
}
else
{
NSString* imageTitle;
if ([[self.photo objectForKey:@"title"] length] > 0)
imageTitle = [self.photo objectForKey:@"title"];
else if ([[self.photo valueForKeyPath:@"description._content"] length] > 0)
imageTitle = [self.photo valueForKeyPath:@"description._content"];
else imageTitle = @"Unknown";
[[self navigationItem] setTitle:imageTitle];
self.scrollView.delegate = self;
self.scrollView.contentSize = self.imageView.image.size;
}
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
double scale = self.imageView.bounds.size.width * 1.0/self.myImage.size.width;
if (scale > self.imageView.bounds.size.height * 1.0/self.myImage.size.height)
scale = self.imageView.bounds.size.height * 1.0/self.myImage.size.height;
NSLog(@"imgview%g, %g",self.imageView.bounds.size.width, self.imageView.bounds.size.height);
NSLog(@"img%g, %g",self.myImage.size.width, self.myImage.size.height);
self.imageView.frame = CGRectMake(0, 0, self.imageView.image.size.width, self.imageView.image.size.height);
[self.scrollView setZoomScale:scale];
}
'dispatch_release (downloadQueue);'를 주석 처리하면 작동합니까? 블록이 실행되기 전에 디스패치 큐를 해제한다고 생각합니다. – Costique
시도했습니다. 아직도 일하지 않고있다. – yoyosir