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市场推广专家,欢迎大家加入我们的团队! - ...
随机推荐
- 3-5年的PHPer常见的面试题
看到有很多,的总结一下,比较适合有一定经验的PHPer 1.平时喜欢哪些php书籍及博客?CSDN.虎嗅.猎云 2.js闭包是什么? 3.for与foreach哪个更快? 4.php鸟哥是谁?能不能讲 ...
- oc调用rest api
无需其他类库 1: - (IBAction)callapi:(id)sender { 2: NSURL *url=[NSURL URLWithString:@"http://..." ...
- iOS-修改Status Bar
一.在info.plist文件中添加一行不但要在 Status bar is initially hidden一行,选择为 YES. 二.在didFinishLaunchingWithOptions方 ...
- android程序---->android多线程下载(一)
多线程下载是加快下载速度的一种方式,通过开启多个线程去执行一个任务,可以使任务的执行速度变快.多线程的任务下载时常都会使用得到断点续传下载,就是我们在一次下载未结束时退出下载,第二次下载时会接着第一次 ...
- 基于openssl的单向和双向认证
1.前言 最近工作涉及到https,需要修改nginx的openssl模块,引入keyless方案.关于keyless可以参考CloudFlare的官方博客: https://blog.cloudfl ...
- 开放产品开发(OPD):产品负责人的工作原则和方法
月26日我将在2014 WOT全球软件技术峰会做相关的一个主题演讲[产品负责人的工作原则和方法],个原则和相应的一些方法. 以下是本次分享内容: 完整版如下,如果你喜欢想下载的话,点击 http:// ...
- elasticsearch配置
配置文件详解1.0版 配置文件位于es根目录的config目录下面,有elasticsearch.yml和logging.yml两个配置,主配置文件是elasticsearch.yml,日志配置文件是 ...
- 转载---CSS3实现曲线阴影和翘边阴影
预备知识 DIV+CSS基础 圆角:border-radius 2D变换:transform:skew && rotate 伪类::before 和 :after 代码 HTML结构代 ...
- 组合数学 - 波利亚定理 --- poj : 2154 Color
Color Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7873 Accepted: 2565 Description ...
- 重构第27天 去除上帝类(Remove God Classes)
理解:本文中的”去除上帝类”是指把一个看似功能很强且很难维护的类,按照职责把自己的属性或方法分派到各自的类中或分解成功能明确的类,从而去掉上帝类. 详解:我们经常可以在一些原来的代码中见到一些类明确违 ...