iOS MBProgressHUD 特效 加载界面
2014-07-28 09:23
176 查看
开源中国iOS客户端学习——(七)MBProgressHUD特效
分类: 菜鸟学iOS的笔记2013-01-1613:55 10711人阅读 评论(9) 收藏 举报
在开源中国iOS客户端中也用到了MBProgressHUD这个特效,主要作用为应用显示一个过渡的作用,常用于打开一个联网页面加载过程,防止出现假死现象,如果网速慢则告诉用户已经在很努力很努力的加载中。
GitHub上下载地址:https://github.com/jdg/MBProgressHUD
源码中也自带了一个Demo,显示13中动画效果,可以根据需要选取其中特效加以使用,使用方法基本一样;使用的时候只加把MBProgressHUD.h和MBProgressHUD.m拖入工程中,在使用的文件中加上#import"MBProgressHUD.h"
在开源中国iOS客户端中只用到一种特效,当我们选取一条资讯查看详细信息时:
我们在跳转到实现的代码部分,在NewsDetail.m的clickFavorite和viewDidLoad方法中
[cpp] view
plaincopy
- (void)clickFavorite:(id)sender
{
UIBarButtonItem * btn = (UIBarButtonItem *)sender;
BOOL isFav = [btn.title isEqualToString:@"收藏此文"];
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
[Tool showHUD:isFav ? @"正在添加收藏":@"正在删除收藏" andView:self.view andHUD:hud];
[[AFOSCClient sharedClient]getPath:isFav ? api_favorite_add : api_favorite_delete
parameters:[NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat:@"%d", [Config Instance].getUID],@"uid",
[NSString stringWithFormat:@"%d", newsID],@"objid",
@"4",@"type", nil] success:^(AFHTTPRequestOperation *operation, id responseObject) {
[hud hide:YES];
[Tool getOSCNotice2:operation.responseString];
ApiError *error = [Tool getApiError2:operation.responseString];
if (error == nil) {
[Tool ToastNotification:operation.responseString andView:self.view andLoading:NO andIsBottom:NO];
return ;
}
switch (error.errorCode)
{
case 1:
{
btnFavorite.title = isFav ? @"取消收藏" : @"收藏此文";
self.singleNews.favorite = !self.singleNews.favorite;
}
break;
case 0:
case -2:
case -1:
{
[Tool ToastNotification:[NSString stringWithFormat:@"错误 %@",error.errorMessage] andView:self.view andLoading:NO andIsBottom:NO];
}
break;
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[hud hide:YES];
[Tool ToastNotification:@"添加收藏失败" andView:self.view andLoading:NO andIsBottom:NO];
}];
}
[cpp] view
plaincopy
- (void)viewDidLoad
{
[super viewDidLoad];
self.tabBarItem.title = @"资讯详情";
self.tabBarItem.image = [UIImage imageNamed:@"detail"];
//WebView的背景颜色去除
[Tool clearWebViewBackground:self.webView];
self.singleNews = [[SingleNews alloc] init];
self.navigationController.title = @"资讯详情";
self.webView.delegate = self;
[self.webView loadHTMLString:@"" baseURL:nil];
if ([Config Instance].isNetworkRunning)
{
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
[Tool showHUD:@"正在加载" andView:self.view andHUD:hud];
NSString *url = [NSString stringWithFormat:@"%@?id=%d",api_news_detail, newsID];
[[AFOSCClient sharedClient] getPath:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
[Tool getOSCNotice2:operation.responseString];
[hud hide:YES];
self.singleNews = [Tool readStrNewsDetail:operation.responseString];
if (self.singleNews == nil) {
[Tool ToastNotification:@"加载失败" andView:self.view andLoading:NO andIsBottom:NO];
return;
}
[self loadData:self.singleNews];
//如果有网络 则缓存它
if ([Config Instance].isNetworkRunning)
{
[Tool saveCache:1 andID:self.singleNews._id andString:operation.responseString];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[hud hide:YES];
if ([Config Instance].isNetworkRunning) {
[Tool ToastNotification:@"错误 网络无连接" andView:self.view andLoading:NO andIsBottom:NO];
}
}];
}
else
{
NSString *value = [Tool getCache:1 andID:newsID];
if (value) {
self.singleNews = [Tool readStrNewsDetail:value];
[self loadData:self.singleNews];
}
else {
[Tool ToastNotification:@"错误 网络无连接" andView:self.view andLoading:NO andIsBottom:NO];
}
}
} TE
相关文章推荐
- IOS基本界面元素window(窗口)\视图(view)介绍及生命周期和加载过程等
- IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
- IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
- 菊花加载第三方--MBprogressHUD 分类: ios技术 2015-02-05 19:21 120人阅读 评论(0) 收藏
- IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
- IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
- IOS欢迎界面Launch Screen动态加载广告
- 简单易懂的ios开发中,上拉加载,下拉刷新界面,初学就能看懂
- 开源中国iOS客户端学习——(七)MBProgressHUD特效
- 开源中国iOS客户端学习——MBProgressHUD特效
- IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
- 开源中国iOS客户端学习——(七)MBProgressHUD特效
- 开源中国iOS客户端学习——(七)MBProgressHUD特效
- ios-上拉加载更多的界面
- 开源中国iOS客户端学习——(七)MBProgressHUD特效
- IOS开发UI篇之──自定义加载等待框(MBProgressHUD)
- 开源中国iOS客户端学习——(七)MBProgressHUD特效
- ios 特效 新思路 :加载gif 动画,然后在动画上增加点击事件即可。
- IOS界面UI设计8之主界面加载以及键盘
- IOS 应用程序启动加载过程(从点击图标到界面显示)