我正在使用Flickr API和ObjectiveFlickr.A构建一个免费的乐器iPhone应用程序。有趣列表中的一张随机照片显示在背景中,但我不能在不知道其大小的情况下将其居中。(这样我就可以重置UIWebView帧)
我已经研究这个问题有一段时间了,如果答案非常简单,请宽恕新手--这是我第一次使用web服务API。=)
因为我在收到有趣提要的响应后才知道照片ID,所以如何在响应上调用flickr.photo.getSizes?这就是我到目前为止所知道的:
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary{
int randomResponse = arc4random() % 49;
photoDict = [[inResponseDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:randomResponse];
NSString *photoID = [photoDict valueForKeyPath:@"id"];
NSLog(@"%@",photoID);
NSURL *photoURL = [flickrContext photoSourceURLFromDictionary:photoDict size:OFFlickrMediumSize];
NSString *htmlSource = [NSString stringWithFormat:
@"<html>"
@"<head>"
@" <style>body { margin: 0; padding: 0; } </style>"
@"</head>"
@"<body>"
@"<img src=\"%@\" />"
@"</body>"
@"</html>"
, photoURL];
[webView loadHTMLString:htmlSource baseURL:nil];
}发布于 2010-04-16 22:00:01
通过将返回的图像加载到UIImageView中,我实现了我想要的行为。这是代码,希望它能帮助到一些人:
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary{
int randomResponse = arc4random() % 49;
photoDict = [[inResponseDictionary valueForKeyPath:@"photos.photo"] objectAtIndex:randomResponse];
NSString *photoID = [photoDict valueForKeyPath:@"id"];
NSLog(@"%@",photoID);
NSURL *photoURL = [flickrContext photoSourceURLFromDictionary:photoDict size:OFFlickrMediumSize];
NSData *receivedData = [[NSData dataWithContentsOfURL:
photoURL] retain];
UIImage *image = [[UIImage alloc] initWithData:receivedData] ;
NSLog(@"%i",image.size);
randomImage.image = image;
//[webView loadHTMLString:htmlSource baseURL:nil];
}https://stackoverflow.com/questions/2649611
复制相似问题