NSURLConnectionでMBProgressHUDを使用しようとしていました。
MBProgressHUDレポートのデモプロジェクトの例:
- (IBAction)showURL:(id)sender {
NSURL *URL = [NSURL URLWithString:@"https://github.com/matej/MBProgressHUD/zipball/master"];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
[connection release];
HUD = [[MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES] retain];
HUD.delegate = self;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
expectedLength = [response expectedContentLength];
currentLength = 0;
HUD.mode = MBProgressHUDModeDeterminate;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
currentLength += [data length];
HUD.progress = currentLength / (float)expectedLength;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
HUD.mode = MBProgressHUDModeCustomView;
[HUD hide:YES afterDelay:2];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[HUD hide:YES];
}
それを実行すると、確定モードのHUDが正常に回転します。
私はこれを実装しようとしましたが、ここに
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
currentLength += [data length];
HUD.progress = currentLength / (float)expectedLength;
}
円は空で、塗りつぶされていません。
リクエストされたURLのサイズに依存するかどうかはわかりません。
ウェブサイトからplist(〜80 kb)をダウンロードするように要求しましたが、円が空のままでコンソールレポートが表示されます
<Error>: void CGPathAddArc(CGPath*, const CGAffineTransform*, CGFloat, CGFloat, CGFloat, CGFloat, CGFloat, bool): invalid value for start or end angle.
私もこのようにしようとしました:
float progress = 0.0f;
while (progress < 1.0f) {
progress += 0.01f;
HUD.progress = progress;
}
しかし、今では円は完全にいっぱいで、アニメーションは実行されていません。
リクエストされたURLのサイズにもよると思いますが、よくわかりません。これを修正する方法を知っている人はいますか?