Skip to content

Commit

Permalink
WNXHuntForCity
Browse files Browse the repository at this point in the history
添加了清理缓存,拨打电话功能能
  • Loading branch information
MacBook committed Jul 21, 2015
1 parent aabb12a commit 49ffb13
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 45 deletions.
30 changes: 11 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
# iOS高仿城觅项目(开发思路和代码)
![抽屉](http://ww3.sinaimg.cn/mw690/0068uRu1gw1eu7gt6f9lpg307r0eakhq.gif)

![首页](http://ww2.sinaimg.cn/mw690/0068uRu1gw1eu74isba6cg307r0eaqv8.gif)

![发现](http://ww1.sinaimg.cn/mw690/0068uRu1gw1eu74iyka0ug307r0eau0x.gif)

![抽屉](http://ww3.sinaimg.cn/mw690/0068uRu1gw1euafbypbwfg307r0eanpd.gif)
![首页部分效果](http://ww2.sinaimg.cn/mw690/0068uRu1gw1euafbuoga1g307r0ea4qq.gif)
![首页效果](http://ww3.sinaimg.cn/mw690/0068uRu1gw1euafcdouwvg307r0ea7lo.gif)
![部分效果](http://ww1.sinaimg.cn/mw690/0068uRu1gw1euafd13tbjg307r0eau0y.gif)
![发现](http://ww1.sinaimg.cn/mw690/0068uRu1gw1euafcmh1l6g307r0eae81.gif)
![消息](http://ww2.sinaimg.cn/mw690/0068uRu1gw1eu74j4wthpg307r0ea7j8.gif)

![搜索](http://ww2.sinaimg.cn/mw690/0068uRu1gw1eu79mzig0xg307r0eadix.gif)

![部分细节](http://ww3.sinaimg.cn/mw690/0068uRu1gw1eu74k888uag307r0ea4qq.gif)

![部分细节](http://ww3.sinaimg.cn/mw690/0068uRu1gw1eu74lyd1hhg307r0eau0z.gif)

![部分细节](http://ww2.sinaimg.cn/mw690/0068uRu1gw1eu74m50no5g307r0ea1l0.gif)

![模糊效果](http://ww3.sinaimg.cn/mw690/0068uRu1gw1eu79pa6um2g307r0eahcl.gif)

![设置](http://ww3.sinaimg.cn/mw690/0068uRu1gw1euafcuka9ug307r0eatdy.gif)
![模糊效果](http://ww3.sinaimg.cn/mw690/0068uRu1gw1euag0qdr3yg307i0dpb29.gif)
![代码注释展示](http://ww4.sinaimg.cn/mw690/0068uRu1gw1eu74eo2alej31kw0yx7oy.jpg)

![代码注释展示](http://ww3.sinaimg.cn/mw690/0068uRu1gw1eu74egddlqj31kw0yn18a.jpg)

还有很多细节就不一一展示了,大家将代码运行下自己查看即可.

###文章链接
Expand All @@ -29,6 +18,9 @@
#####如有任何问题都可以在博客下留言,我会逐一回复

#### [点击链接gitHub](http://www.jianshu.com/p/d5ea6c9d65fd)
希望小手能顺便点一下右上角的⭐️Star ^_^,朋友的鼓励和支持是我继续分享的动力
##### 希望小手能顺便点一下右上角的⭐️Star ^_^,朋友的鼓励和支持是我继续分享的动力

#### [我的微博](http://weibo.com/5622363113/profile?rightmod=1&wvr=6&mod=personinfo)


####请直接打开`WNXHuntForCity.xcworkspace`运行工程![打开](http://ww4.sinaimg.cn/mw690/0068uRu1gw1eu7cyp74l7j307k06eaac.jpg)而不要打开`WNXHuntForCity.xcodeproj`
Binary file not shown.
31 changes: 26 additions & 5 deletions WNXHuntForCity/Classes/Detail/Controller/WNXDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//选择View的高度
static const CGFloat SelectViewHeight = 45;

@interface WNXDetailViewController () <UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, WNXSelectViewDelegate, WNXDetailFootViewDelegate, MAMapViewDelegate>
@interface WNXDetailViewController () <UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate, WNXSelectViewDelegate, WNXDetailFootViewDelegate, MAMapViewDelegate, UIActionSheetDelegate>

/** 地图view */
@property (nonatomic, strong) MAMapView *mapView;
Expand Down Expand Up @@ -87,6 +87,9 @@ @interface WNXDetailViewController () <UITableViewDataSource, UITableViewDelegat
/** 信息tableview的数据 */
@property (nonatomic, strong) NSMutableArray *infoDatas;

/** 电话提示 */
@property (nonatomic, strong) UIActionSheet *actionSheet;

@end

@implementation WNXDetailViewController
Expand Down Expand Up @@ -243,7 +246,7 @@ - (void)setUI
[self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(39.906598, 116.400673) animated:YES];
self.mapView.delegate = self;
self.mapView.zoomLevel = 14;

//添加自定义图片
MAPointAnnotation *pointAnnotation = [[MAPointAnnotation alloc] init];
pointAnnotation.coordinate = CLLocationCoordinate2DMake(39.906598, 116.400673);
Expand Down Expand Up @@ -457,7 +460,7 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
} else {
//信息tableVIew
WNXInfoModel *model = self.infoDatas[indexPath.row];

return model.cellHeight;
}
}
Expand Down Expand Up @@ -486,7 +489,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return [WNXRmdPicCell cellWithTabelView:tableView rmdPicModel:rmdCellModel];
}
}

WNXInfoCell *cell = [WNXInfoCell infoCellWithTableView:tableView];
cell.model = self.infoDatas[indexPath.row];
if (self.infoDatas.count - 1 == indexPath.row) {
Expand All @@ -503,9 +506,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
//地图
WNXMapViewController *mapVC = [[WNXMapViewController alloc] init];
[self.navigationController pushViewController:mapVC animated:YES];

} else if (indexPath.row == 1) {
WNXInfoModel *model = self.infoDatas[indexPath.row];
//打电话
self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择要播的电话" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:model.title otherButtonTitles:model.subTitle, nil];
[self.actionSheet showInView:self.view];
}
}

Expand Down Expand Up @@ -591,6 +597,21 @@ - (void)sharedBtnClick
[view showUnLoginViewToView:self.view];
}

#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//不是取消按钮
if (buttonIndex != actionSheet.numberOfButtons - 1) {
UIApplication *app = [UIApplication sharedApplication];
//这里只有写了两种情况,实际是应该遍历服务器返回的数据,然后判断和buttonIndex
WNXInfoModel *model = self.infoDatas[1];
NSString *phoneNum = buttonIndex == 0 ? model.title : model.subTitle;
[app openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", phoneNum]]];
}

actionSheet = nil;
}

- (void)dealloc
{
WNXLog(@"Detail被销毁了");
Expand Down
13 changes: 0 additions & 13 deletions WNXHuntForCity/Classes/Detail/Model/WNXHomeCellModel.m

This file was deleted.

2 changes: 1 addition & 1 deletion WNXHuntForCity/Classes/Detail/View/WNXInfoCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ - (void)setModel:(WNXInfoModel *)model
[self layoutIfNeeded];

if (!self.titleSecondLabel.hidden) {
model.cellHeight = CGRectGetMaxY(self.titleSecondLabel.frame) + 10;
model.cellHeight = CGRectGetMaxY(self.titleSecondLabel.frame) + 20;
} else {
model.cellHeight = CGRectGetMaxY(self.titleOneLabel.frame) + 10;
}
Expand Down
79 changes: 72 additions & 7 deletions WNXHuntForCity/Classes/Seting/Controller/WNXSetingViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
#import "WNXSetingView.h"
#import "WNXMenuButton.h"
#import "AppDelegate.h"
#import <SDWebImageManager.h>

@interface WNXSetingViewController ()
#define WNXCachesPath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]

@interface WNXSetingViewController () <UIAlertViewDelegate>
@property (strong, nonatomic) UIScrollView *scrollView;

/** 新浪登陆view */
Expand All @@ -27,7 +30,8 @@ @interface WNXSetingViewController ()
@property (nonatomic, strong) WNXSetingView *judgeView;
/** 退出登陆按钮 */
@property (nonatomic, strong) WNXMenuButton *logoutButton;

/** 缓存弹出提示框 */
@property (nonatomic, strong) UIAlertView *alertView;
@end

@implementation WNXSetingViewController
Expand Down Expand Up @@ -78,7 +82,7 @@ - (void)viewDidLoad {
[self.logoutButton setTitle:@"退出登录" forState:UIControlStateNormal];
[self.logoutButton addTarget:self action:@selector(logoutButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:self.logoutButton];

}

- (void)viewAddSetingViewWithSetingView:(WNXSetingView *)view frame:(CGRect)frame tag:(WNXSetingViewType)tag
Expand All @@ -97,12 +101,38 @@ - (void)viewClick:(UITapGestureRecognizer *)tap
//判断点击了那个view
switch (tap.view.tag) {
case WNXSetingViewTypeSina:
if(self.logoutButton.hidden) {
self.logoutButton.hidden = NO;
}
break;
case WNXSetingViewTypeWeiXin:
if (self.logoutButton.hidden) {
self.logoutButton.hidden = NO;
}
break;
case WNXSetingViewTypeClean:


//拿到要清理的路径,其实就是caches的路径,一般像这种很多地方都会用到的地方真好搞成宏,不过现在苹果不提倡用宏了
//在swift中可以定义成全局的常量
//遍历caches,将内部的文件大小计算出来,点击确认删除的话直接删除全部文件,如果有不想清理的文件,可以在遍历文件时根据路径过滤掉
{
NSString *path = WNXCachesPath;
NSFileManager *fileManager=[NSFileManager defaultManager];
float folderSize;
if ([fileManager fileExistsAtPath:path]) {
//拿到算有文件的数组
NSArray *childerFiles = [fileManager subpathsAtPath:path];
//拿到每个文件的名字,如有有不想清除的文件就在这里判断
for (NSString *fileName in childerFiles) {
//将路径拼接到一起
NSString *fullPath = [path stringByAppendingPathComponent:fileName];
folderSize += [self fileSizeAtPath:fullPath];
}

self.alertView = [[UIAlertView alloc] initWithTitle:@"清理缓存" message:[NSString stringWithFormat:@"缓存大小为%.2fM,确定要清理缓存吗?", folderSize] delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[self.alertView show];
self.alertView.delegate = self;
}
}
break;
case WNXSetingViewTypeFeedback:
{
Expand All @@ -113,15 +143,16 @@ - (void)viewClick:(UITapGestureRecognizer *)tap
break;
case WNXSetingViewTypeJudge:
{
UIApplication *app = [UIApplication sharedApplication];
UIApplication *app = [UIApplication sharedApplication];
NSURL *itunesPath = [NSURL URLWithString:@"http://www.jianshu.com/p/8b0d694d1c69"];
[app openURL:itunesPath];
}
break;

default:
break;
}

}

//退出登录
Expand All @@ -130,4 +161,38 @@ - (void)logoutButtonClick
self.logoutButton.hidden = YES;
}

#pragma mark UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex) {
//点击了确定,遍历整个caches文件,将里面的缓存清空
NSString *path = WNXCachesPath;
NSFileManager *fileManager=[NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSArray *childerFiles=[fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles) {
//如有需要,加入条件,过滤掉不想删除的文件
NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
[fileManager removeItemAtPath:absolutePath error:nil];
}
}
}

self.alertView = nil;
}

//计算单个文件夹的大小
-(float)fileSizeAtPath:(NSString *)path{

NSFileManager *fileManager=[NSFileManager defaultManager];

if([fileManager fileExistsAtPath:path]){

long long size=[fileManager attributesOfItemAtPath:path error:nil].fileSize;

return size/1024.0/1024.0;
}
return 0;
}
@end

0 comments on commit 49ffb13

Please sign in to comment.