IOS客户端Coding项目记录(四)
1:打开Xcode,然后闪退,报加载某库出现异常
如/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib
这个是Xcode的bug,我的情况是打开某个项目会出现这个问题
解决办法:这还是缓存问题,详见第五点(、XCode5由于缓存问题引起了很多奇怪的问题,所以清除缓存有时会起到大作用:),清除缓存再运行,一切正常。
进入步骤,按option键进入资源库,Developer—xcode—DerivedData把里面的文件清除就可以
2:加快CocoaPod安装插件的速度
(这样也解决一些插件下载时失败的问题,因为一些源代码的内容是不必要,而提供的地址却连接不到,导致报错,而无法更新)
$ pod install --no-repo-update
3:userInteractionEnabled属性
当视图对象的userInteractionEnabled设置为NO的时候,用户触发的事件,如触摸,键盘等,将会被该视图忽略(其他视图照常响应),并且该视图对象也会从事件响应队列中被移除。 当userInteractionEnabled设为YES时,则事件可以正常的传递给该视图对象。 userInteractionEnabled的属性默认值就是YES。
EaseUserHeaderView *headerView = [[EaseUserHeaderView alloc] init];
headerView.userInteractionEnabled = YES;
4:字符串显示问题,同一行不同的效果
调用:
[_fansCountBtn setAttributedTitle:[self getStringWithTitle:@"粉丝" andValue:_curUser.fans_count.stringValue] forState:UIControlStateNormal]; 方法:
- (NSMutableAttributedString*)getStringWithTitle:(NSString *)title andValue:(NSString *)value{
NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", value, title]];
[attriString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:],
NSForegroundColorAttributeName : [UIColor whiteColor]}
range:NSMakeRange(, value.length)]; [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:],
NSForegroundColorAttributeName : [UIColor whiteColor]}
range:NSMakeRange(value.length+, title.length)];
return attriString;
} 另:label可以调用sizeToFit来调整内容适应 _userLabel.text = _curUser.name;
[_userLabel sizeToFit];
5:NSArray中使用firstObject和lastObject
NSArray有lastObject方法用来获取数组最后一个对象,firstObject来获取数组第一个对象,NSArray中使用firstObject和lastObject的好处在于,当数组为空时,返回nil,而不会报错。当数组为空,使用myArray[]时,会报错。 NSNumber *firstLevel = nil, *secondLevel = nil;
NSArray *locationArray = [_curUser.location componentsSeparatedByString:@" "];
if (locationArray.count == ) {
firstLevel = [AddressManager indexOfFirst:[locationArray firstObject]];
secondLevel = [AddressManager indexOfSecond:[locationArray lastObject] inFirst:[locationArray firstObject]];
}
6:日期控件ActionSheetDatePicker 多级控件ActionSheetStringPicker
小实例:
NSDate *curDate = [NSDate dateFromString:_curUser.birthday withFormat:@"yyyy-MM-dd"];
if (!curDate) {
curDate = [NSDate dateFromString:@"1990-01-01" withFormat:@"yyyy-MM-dd"];
}
ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc] initWithTitle:nil datePickerMode:UIDatePickerModeDate selectedDate:curDate doneBlock:^(ActionSheetDatePicker *picker, NSDate *selectedDate, id origin) {
NSString *preValue = weakSelf.curUser.birthday;
weakSelf.curUser.birthday = [selectedDate string_yyyy_MM_dd];
[weakSelf.myTableView reloadData];
[[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {
if (data) {
weakSelf.curUser = data;
}else{
weakSelf.curUser.birthday = preValue;
}
[weakSelf.myTableView reloadData];
}];
} cancelBlock:^(ActionSheetDatePicker *picker) {
NSLog(@"%@", picker.description);
} origin:self.view];
picker.minimumDate = [[NSDate date] offsetYear:-];
picker.maximumDate = [NSDate date];
[picker showActionSheetPicker]; 小实例: [ActionSheetStringPicker showPickerWithTitle:nil rows:@[[AddressManager firstLevelArray], [AddressManager secondLevelMap]] initialSelection:@[firstLevel, secondLevel] doneBlock:^(ActionSheetStringPicker *picker, NSArray * selectedIndex, NSArray *selectedValue) {
NSString *preValue = weakSelf.curUser.location;
NSString *location = [selectedValue componentsJoinedByString:@" "];
weakSelf.curUser.location = location;
[weakSelf.myTableView reloadData];
[[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {
if (data) {
weakSelf.curUser = data;
}else{
weakSelf.curUser.location = preValue;
}
[weakSelf.myTableView reloadData];
}];
} cancelBlock:nil origin:self.view]; 小实例: [ActionSheetStringPicker showPickerWithTitle:nil rows:@[@[@"男", @"女", @"未知"]] initialSelection:@[_curUser.sex] doneBlock:^(ActionSheetStringPicker *picker, NSArray * selectedIndex, NSArray *selectedValue) {
NSNumber *preValue = weakSelf.curUser.sex;
weakSelf.curUser.sex = [selectedIndex firstObject];
[weakSelf.myTableView reloadData];
[[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {
if (data) {
weakSelf.curUser = data;
}else{
weakSelf.curUser.sex = preValue;
}
[weakSelf.myTableView reloadData];
}];
} cancelBlock:nil origin:self.view];
7:代码自动布局Masonry插件
Masonry支持哪一些属性@property (nonatomic, strong, readonly) MASConstraint *left;
@property (nonatomic, strong, readonly) MASConstraint *top;
@property (nonatomic, strong, readonly) MASConstraint *right;
@property (nonatomic, strong, readonly) MASConstraint *bottom;
@property (nonatomic, strong, readonly) MASConstraint *leading;
@property (nonatomic, strong, readonly) MASConstraint *trailing;
@property (nonatomic, strong, readonly) MASConstraint *width;
@property (nonatomic, strong, readonly) MASConstraint *height;
@property (nonatomic, strong, readonly) MASConstraint *centerX;
@property (nonatomic, strong, readonly) MASConstraint *centerY;
@property (nonatomic, strong, readonly) MASConstraint *baseline; 小实例: if (!_titleL) {
_titleL = [[UILabel alloc] init];
[self.contentView addSubview:_titleL];
_titleL.font = [UIFont systemFontOfSize:];
_titleL.textColor = [UIColor blackColor];
}
if (!_valueL) {
_valueL = [[UILabel alloc] init];
_valueL.numberOfLines = ;
[self.contentView addSubview:_valueL];
_valueL.font = [UIFont systemFontOfSize:];
_valueL.textColor = [UIColor colorWithHexString:@"0x999999"];
} [_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.height.mas_equalTo();
make.top.equalTo(self.contentView).offset();
make.width.mas_equalTo(kScreen_Width - *kPaddingLeftWidth);
}];
[_valueL mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_titleL.mas_bottom).offset();
make.left.right.equalTo(_titleL);
}];
实例(注意右边跟下边要用负数):
UIView *sv=[UIView new];
sv.backgroundColor=[UIColor redColor];
[self.view addSubview:sv];
//定义一个剧中大小
[sv mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view);
make.size.mas_equalTo(CGSizeMake(300, 300));
}];
UIView *childView=[UIView new];
childView.backgroundColor=[UIColor greenColor];
[sv addSubview:childView];
//相对父视图
[childView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(sv.mas_left).with.offset(20);
make.top.equalTo(sv.mas_top).with.offset(10);
make.right.equalTo(sv.mas_right).with.offset(-20);
make.height.equalTo(@200);
}];
UIView *otherChildView=[UIView new];
otherChildView.backgroundColor=[UIColor yellowColor];
[sv addSubview:otherChildView];
//相对父视图跟兄弟视图
[otherChildView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(childView.mas_bottom).with.offset(10);
make.bottom.equalTo(sv.mas_bottom).with.offset(-10);
make.left.equalTo(sv.mas_left).with.offset(10);
make.width.mas_equalTo(@240);
}];
另一实例:
// 先给redBtn添加约束
[redBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// 添加左、上边距约束
// 添加上边距约束
make.top.mas_equalTo(100);
// 添加左边距约束
make.left.mas_equalTo(20);
// 添加右边距约束
make.right.mas_equalTo(-20);
}];
// 还是老规矩 先初始化一个btn
UIButton * blueBtn = [UIButton new];
blueBtn.backgroundColor = [UIColor blueColor];
[self.view addSubview:blueBtn];
// 给蓝色btn添加约束
[blueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
// 添加右、下边距约束
// make.bottom.and.right.mas_equalTo(-20);
// 添加下边距约束
make.bottom.mas_equalTo(-20);
// 添加右边距约束
make.right.mas_equalTo(-20);
// 添加高度约束,让高度等于红色Btn
make.height.equalTo(redBtn);
// 添加上边距约束(上边距 = 红色btn的下边框 + 偏移量20)
make.top.equalTo(redBtn.mas_bottom).offset(20);
// 添加左边距(左边距 = 父容器纵轴中心 + 偏移量0)
make.left.equalTo(weakSelf.view.mas_centerX).offset(0);
}];
好文章:http://www.cocoachina.com/ios/20141219/10702.html
关于更新布局mas_updateConstraints的运用 实例一: #import "Masonry.h" @interface ViewController5() @property(strong,nonatomic)UILabel *myLabel; @end @implementation ViewController5 -(void)viewDidLoad
{
[super viewDidLoad];
self.myLabel=[UILabel new];
self.myLabel.text=@"GOOD";
self.myLabel.backgroundColor=[UIColor blueColor];
[self.view addSubview:self.myLabel]; [self.myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.view.mas_left).with.offset();
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(-);
make.size.mas_equalTo(CGSizeMake(, ));
}];
}
- (IBAction)actionBtn:(id)sender {
CGFloat newBottom=-;
//修改布局
[_myLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(newBottom);
}]; //要进行layoutIfNeeded 才有效果
[self.myLabel layoutIfNeeded];
}
@end 实例二:
(修改键盘跟输入框的隐藏问题)
#import "Masonry.h" @interface ViewController4 () @property (strong, nonatomic) UITextField *textField; @end @implementation ViewController4 - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self];
} - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. __weak typeof(self) weakSelf = self; _textField = [UITextField new];
_textField.backgroundColor = [UIColor redColor];
[self.view addSubview:_textField]; [_textField mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo();
make.centerX.equalTo(weakSelf.view);
make.bottom.mas_equalTo();
make.height.mas_equalTo();
}]; // 注册键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrameNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHideNotification:) name:UIKeyboardWillHideNotification object:nil];
} - (void)keyboardWillChangeFrameNotification:(NSNotification *)notification { // 获取键盘基本信息(动画时长与键盘高度)
NSDictionary *userInfo = [notification userInfo];
CGRect rect = [userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGFloat keyboardHeight = CGRectGetHeight(rect);
CGFloat keyboardDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 修改下边距约束
[_textField mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo(-keyboardHeight);
}]; // 更新约束
[UIView animateWithDuration:keyboardDuration animations:^{ [self.view layoutIfNeeded];
}];
} - (void)keyboardWillHideNotification:(NSNotification *)notification { // 获得键盘动画时长
NSDictionary *userInfo = [notification userInfo];
CGFloat keyboardDuration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]; // 修改为以前的约束(距下边距0)
[_textField mas_updateConstraints:^(MASConstraintMaker *make) { make.bottom.mas_equalTo();
}]; // 更新约束
[UIView animateWithDuration:keyboardDuration animations:^{ [self.view layoutIfNeeded];
}];
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesBegan:touches withEvent:event];
[self.view endEditing:YES];
} @end
IOS客户端Coding项目记录(四)的更多相关文章
- IOS客户端Coding项目记录导航
IOS客户端Coding项目记录(一) a:UITextField设置出现清除按键 b:绘画一条下划线 表格一些设置 c:可以定义表头跟底部视图(代码接上面) d:隐藏本页的导航栏 e:UIEdge ...
- IOS客户端Coding项目记录(五)
1:统一修改导航栏的样式,在 AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWit ...
- IOS客户端Coding项目记录(三)
18:图片视图几种填充样式 _imgView.contentMode = UIViewContentModeScaleAspectFill; 如下: typedef NS_ENUM(NSInteger ...
- IOS客户端Coding项目记录(一)
1:UITextField设置出现清除按键 self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 说明: UITextFi ...
- IOS客户端Coding项目记录(六)
1:获取某一行的坐标 UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow: ...
- IOS客户端Coding项目记录(二)
9:第三方插件整理 JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/ 美化按键:BButton https://github.com/m ...
- 开源项目在真机调试(Coding iOS 客户端为例)
一.前言 iOS 13学习系列:如何在github下载开源项目到本地(Coding iOS 客户端为例)已经把 Coding iOS 客户端源码下载到本地. 但项目进行真机调试遇到很多问题. 二.问题 ...
- 如何在github下载开源项目到本地(Coding iOS 客户端为例)
一.前言 以 Coding iOS 客户端 为例讲解如何在github下载开源项目到本地 github地址:https://github.com/Coding/Coding-iOS 二.分析 根据项目 ...
- “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX
"快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...
随机推荐
- 【cs229-Lecture17】离散与维数灾难
主要内容: 解决MDP问题的算法: 离散化: 模型MDP的同化型: (model/similator) 拟合值迭代算法: Q函数: 近似政策迭代: 笔记转自:http://blog.csdn.net/ ...
- vmware workstation11+centos7+lnmp一键安装包 环境搭建
vmware workstation11 1.下载:http://pan.baidu.com/s/1gecipOJ 2.安装:直接下一步. centos7 1.下载:网易镜像 http://mirro ...
- Unity 模型导入导出
从3DMAX导出,参考: http://tieba.baidu.com/p/2807225555 -> 使用3dmax 2013,会自带导出 fbx 的功能 -> 从 3dmax 导出 - ...
- [ML] Naive Bayes for email classification
20 Newsgroups (Original) Author: Jeffrey H 1. Introduction This is only a test report for naive baye ...
- 浅谈C++的this指针
之所以写这篇文章,主要是为了回答网友 zhancaihua123同学的下面几个问题: father* p=new son;p->disp(...);father是父类,son是子类.disp是一 ...
- Vue基础---->VueJS的使用(二)
组件(Component)是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素,Vue.js 的编译器为它添加特殊功能.今天我们就来学习一 ...
- SQL Server临界点游戏——为什么非聚集索引被忽略!
当我们进行SQL Server问题处理的时候,有时候会发现一个很有意思的现象:SQL Server完全忽略现有定义好的非聚集索引,直接使用表扫描来获取数据.我们来看看下面的表和索引定义: CREATE ...
- Angular系列----AngularJS入门教程04:迭代器过滤(转载)
我们在上一步做了很多基础性的训练,所以现在我们可以来做一些简单的事情喽.我们要加入全文检索功能(没错,这个真的非常简单!).同时,我们也会写一个端到端测试,因为一个好的端到端测试可以帮上很大忙.它监视 ...
- [Solution] Microsoft Windows 服务(3) 使用Quartz.net定时任务
Quartz是OpenSymphony开源组织在Job scheduling领域又一个开源项目,Quartz.net 就是Quartz的移植版本.Quartz可以用来创建简单或为运行十个,百个,甚至是 ...
- KMP算法 --- 深入理解next数组
在KMP算法中有个数组,叫做前缀数组,也有的叫next数组. 每一个子串有一个固定的next数组,它记录着字符串匹配过程中失配情况下可以向前多跳几个字符. 当然它描述的也是子串的对称程度,程度越高,值 ...