我正在使用 Flickr API 和 ObjectiveFlickr 构建一个免费的乐器 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];
}