奋斗了整整两个星期的时间,终于把第一个项目给完成了,对于菜鸟的我来说,真不是一件简单的事情,其中的收获对我来说,非常有意义,所以借此机会进行一下总结,以方便以后更好的开发……
首先
1.在设置款APP时,考虑在页面中设置导航控制器,使用Navigation bar和Navigation toolbar可以方便设置顶部和底部菜单的文字图片以及左右放置的位置,通过设置了 self.edgesForExtendedLayout ,UIRectEdgeAll的时候会让tableView从导航栏下移44px,设置为UIRectEdgeNone的时候,刚好在导航栏下面:
self.edgesForExtendedLayout=UIRectEdgeNone;
还有通过使用导航栏的“titleTextAttributes”属性来自定义的文本样式:
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
2.对页面进行布局,使用UIScrollView显示超过你能放屏幕的内存的内容,其中,contentsize是UIScrollView的一个属性,它是一个CGSize,是由核心图形所定义的架构,定义了你可以滚轴内容的宽度和高度;
3.由于前面使用scrollView进行滚动,但是滚动幅度太大,给用户的体验感不好,怎么办。这时偏移量就派上了用场,使用contentOffset偏移量对其进行限制:
//偏移量
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint point=scrollView.contentOffset;
if (point.y<=0) {
scrollView.contentOffset=CGPointMake(0,0);
}
if (point.y>=Screen_Width*4-Screen_Width/3-60) {
scrollView.contentOffset=CGPointMake(0, Screen_Width*4-Screen_Width/3-60);
}
}
4.使用UIButton进行按钮的推送,UIButton的类是一个UIControl子类,它实现了在触摸屏上的按钮。设定的目标和行动方法都继承自UIControl。这个类提供了方法来设置标题,图像,按钮等外观属性。
例如:
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
5.通过属性来进行对几个页面的传值:
例如:
从introduceViewController页面传到pushToViewController
@interface introduceViewController : UIViewController
@property (nonatomic,strong)NSString *foodName;
@end
@interface pushToViewController ()
introduceViewController *introduce = [introduceViewController new];
introduce.foodName = transValue;
@end
6.使用网络请求请求数据,使用第三方开源库AFNetworking
目前比较推荐的iOS网络请求组件,默认网络请求是异步,通过block回调的方式对返回数据进行处理。
需要注意的是AFNetworking对服务器返回的ContentType要求比较严格,默认只支持application/json的返回。所以可能需要添加对text/html返回的支持,否则可能无法获得返回数据。
SDWebImage
也是iOS最常用的一个组件,用户加载网络图片,可以缓存到本地。大概原理时,第一次加载后,会根据url加密作为文件名缓存在本地,如果再次加载图片时,就直接从本地加载。用着也比较简单。
+(void)xxxx{
// 如果要检测网络状态的变化,必须用检测管理器的单例的startMonitoring
[[AFNetworkReachabilityManager sharedManager] startMonitoring];
// 检测网络连接的单例,网络变化时的回调方法
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
if((status = AFNetworkReachabilityStatusNotReachable)) {
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:@"无网络",@"info", nil];
}
}];
}
+(void)netWorkWithPath:(NSString *)path Params:(NSDictionary *)params CallBack:(CallBack)callback{
path = [DomainString stringByAppendingString:path];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];
[manager GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
callback(responseObject,SuccessType);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:error.debugDescription,@"info", nil];
callback(info,FailedType);
}];
}
[NetWork netWorkWithPath:@"getCategories2.aspx" Params:[NSDictionary dictionary] CallBack:^(NSDictionary *info, NetType type) {
switch (type) {
case SuccessType:
{
NSLog(@"s info = %@",info[@"data"]);
NSArray *array=info[@"data"];
NSDictionary *dictionary=array[0];
dataSource=dictionary[@"items"];
[self case];
}
break;
case FailedType:
{
}
break;
case NotNetType:
{
}
break;
default:
break;
}
}];
}
7.根据文字多少来计算所需要的高度
//根据文字多少来计算需要多少高度。
CGSize titleSize = [description1 boundingRectWithSize:CGSizeMake(Screen_Width-100, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;
8.清除缓存
-(void)buttonAction:(UIButton *)sender{
[[[UIAlertView alloc]initWithTitle:@"清理缓存" message:@"是否要清除您的缓存" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]show];
[[SDImageCache sharedImageCache]cleanDisk];
}
9.在search中加入3D Sphere View球体来实现可以自动旋转或者手动旋转的3D球形标签,点击标签会放大该标签。
for (NSInteger i = 0; i < array.count; i ++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:[NSString stringWithFormat:@"%@", array[i]] forState:UIControlStateNormal];
[btn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
btn.titleLabel.font = [UIFont systemFontOfSize:17];
btn.frame = CGRectMake(0, 0, 60, 20);
//随机自定义颜色
int red = arc4random_uniform(256);
int green = arc4random_uniform(256);
int blue = arc4random_uniform(256);
btn.backgroundColor = [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0];
[btn addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[array addObject:btn];
btn.titleLabel.adjustsFontSizeToFitWidth=YES;
[sphereView addSubview:btn];
}
[sphereView setCloudTags:array];
sphereView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:sphereView];
}
- (void)buttonPressed:(UIButton *)btn
{
[sphereView timerStop];
[UIView animateWithDuration:0.3 animations:^{
btn.transform = CGAffineTransformMakeScale(2., 2.);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3 animations:^{
btn.transform = CGAffineTransformMakeScale(1., 1.);
} completion:^(BOOL finished) {
[sphereView timerStart];
}];
}];
10.最后shareSDK分享:
(1)导入官方下载的ShareSDK ,
(2)引入相关的库,
(3)在项目的AppDelegate中一般情况下有三个操作,第一是注册ShareSDK,第二是注册各个平台的账号,第三是关于微信等应用的回调处理。
(4)信息分享。
(5)登录、登出、获取授权信息、关注制定微博
IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。关于第三方登录和分享,建议第三方分享模块不用自己特殊设计
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ShareSDK registerApp:@"b17757a6da05"
activePlatforms:@[@(SSDKPlatformTypeSinaWeibo),@(SSDKPlatformTypeWechat)]
onImport:^(SSDKPlatformType platformType)
{
switch (platformType)
{
case SSDKPlatformTypeWechat:
[ShareSDKConnector connectWeChat:[WXApi class]];
break;
/* case SSDKPlatformTypeQQ:
[ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
break;*/
case SSDKPlatformTypeSinaWeibo:
[ShareSDKConnector connectWeibo:[WeiboSDK class]];
break;
default:
break;
}
}
onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
{
switch (platformType)
{
case SSDKPlatformTypeSinaWeibo:
//设置新浪微博应用信息,其中authType设置为使用SSO+Web形式授权
[appInfo SSDKSetupSinaWeiboByAppKey:@"473012490"
appSecret:@"9375a685b61cd04a88d66beaf903e7fb"
redirectUri:@"http://www.sharesdk.cn"
authType:SSDKAuthTypeBoth];
break;
case SSDKPlatformTypeWechat:
[appInfo SSDKSetupWeChatByAppId:@"wx00508b6947478841"
appSecret:@"1601f0ce582aa2377a8308941ed84d30"];
break;
/* case SSDKPlatformTypeQQ:
[appInfo SSDKSetupQQByAppId:@"100371282"
appKey:@"aed9b0303e3ed1e27bae87c33761161d"
authType:SSDKAuthTypeBoth];
break;*/
default:
break;
}
}];
return YES;
}
这是我第一次做项目,第一写项目总结,写得不是很好,但是凡事都会有第一次,经历了这个,自己也是收获了很多的,而此总结则是告诫自己。革命尚未成功,我还需努力。。。