UIActivityIndi​​catorView 用于为 URL 加载的 UIImage

发布于 2024-12-21 15:33:42 字数 121 浏览 0 评论 0原文

我有一个从 URL 加载的 UIImage ,我想在加载图像时显示一个 UIActivityIndi​​catorView 动画。有人可以帮助我吗?

谢谢大家。

I have an UIImage that is loaded from a URL, and i want to show an UIActivityIndicatorView animating while the image loads. Someone can help me?

Thanks for all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-12-28 15:33:42

所以你想在访问服务器时使用UIActivityIndi​​cator

首先在连接调用时创建指示器,然后在连接完成加载时删除活动指示器

//call this when connection start
UIActivityIndicator *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(140, 236, 37, 37);
[activityIndicator startAnimating];
[self.view addSubview:activityIndicator];
self.view.userInteractionEnabled = NO;

//remove activity indicator while connection did finish loadin
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
    self.view.userInteractionEnabled = YES;
}

So u want to use the UIActivityIndicator while accessing the server.

First create the indicator while the connection call, and when connection didfinishloading remove the activity indicator

//call this when connection start
UIActivityIndicator *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(140, 236, 37, 37);
[activityIndicator startAnimating];
[self.view addSubview:activityIndicator];
self.view.userInteractionEnabled = NO;

//remove activity indicator while connection did finish loadin
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
    self.view.userInteractionEnabled = YES;
}
超可爱的懒熊 2024-12-28 15:33:42

首先在 xib 中添加 Activity 指示器并连接 UIActivity Indicator 的对象。

单击 xib 中的“停止时隐藏”。

然后,

-(void)FetchFromServer

{

NSURLRequest* updateRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:@"Write Your Url Here"]];

NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:updateRequest  delegate:self];

[connection start];

[activityIndicator startAnimating];

}

然后在代表中,

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

UIImage *img = [UIImage imageWithData: data];

myImageView.image=img;

[activityIndicator stopAnimating];

}

First of all add Activity indicator in xib and connect object of the UIActivity Indicator.

Click "Hides when Stopped" in the xib.

Then,

-(void)FetchFromServer

{

NSURLRequest* updateRequest = [NSURLRequest requestWithURL: [NSURL URLWithString:@"Write Your Url Here"]];

NSURLConnection* connection = [[NSURLConnection alloc] initWithRequest:updateRequest  delegate:self];

[connection start];

[activityIndicator startAnimating];

}

And then in the delegate,

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

UIImage *img = [UIImage imageWithData: data];

myImageView.image=img;

[activityIndicator stopAnimating];

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文