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项目记录(四)的更多相关文章

  1. IOS客户端Coding项目记录导航

    IOS客户端Coding项目记录(一) a:UITextField设置出现清除按键 b:绘画一条下划线  表格一些设置 c:可以定义表头跟底部视图(代码接上面) d:隐藏本页的导航栏 e:UIEdge ...

  2. IOS客户端Coding项目记录(五)

    1:统一修改导航栏的样式,在 AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWit ...

  3. IOS客户端Coding项目记录(三)

    18:图片视图几种填充样式 _imgView.contentMode = UIViewContentModeScaleAspectFill; 如下: typedef NS_ENUM(NSInteger ...

  4. IOS客户端Coding项目记录(一)

    1:UITextField设置出现清除按键 self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 说明: UITextFi ...

  5. IOS客户端Coding项目记录(六)

    1:获取某一行的坐标 UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow: ...

  6. IOS客户端Coding项目记录(二)

    9:第三方插件整理 JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/ 美化按键:BButton https://github.com/m ...

  7. 开源项目在真机调试(Coding iOS 客户端为例)

    一.前言 iOS 13学习系列:如何在github下载开源项目到本地(Coding iOS 客户端为例)已经把 Coding iOS 客户端源码下载到本地. 但项目进行真机调试遇到很多问题. 二.问题 ...

  8. 如何在github下载开源项目到本地(Coding iOS 客户端为例)

    一.前言 以 Coding iOS 客户端 为例讲解如何在github下载开源项目到本地 github地址:https://github.com/Coding/Coding-iOS 二.分析 根据项目 ...

  9. “快的打车”创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - V2EX

    "快的打车"创始人陈伟星的新项目招人啦,高薪急招Java服务端/Android/Ios 客户端研发工程师/ mysql DBA/ app市场推广专家,欢迎大家加入我们的团队! - ...

随机推荐

  1. webkit特有的css属性

    内容参见:http://css-infos.net/properties/webkit 具体的定义网页里有详细说明.做有一些html5的应用的时候如果不能很好的适应手机,可以到这上面去找找方法-web ...

  2. Android应用安全之外部动态加载DEX文件风险

    1. 外部动态加载DEX文件风险描述 Android 系统提供了一种类加载器DexClassLoader,其可以在运行时动态加载并解释执行包含在JAR或APK文件内的DEX文件.外部动态加载DEX文件 ...

  3. 同时支持控制台和MFC窗口程序的APP

    BOOL CMyApp::InitInstance() { if ( m_bShowGui==FALSE ) { FILE *stream = NULL; AllocConsole(); // 开辟控 ...

  4. tomcat6 使用comet衍生出的两个额外问题

    开发了一个轮询推送功能,网上也有很多文章讲这个就不说怎么做的了.现在发现两个问题: 一:就是登录进主页面后,由于浏览器在不停轮询,导致后端认为前端一直在操作,而正常设定的session超时就跳转到登录 ...

  5. ionic 通过下载apk升级App

    上篇通过更新文件升级APP,如果遇到了比如更新插件之类的问题,上篇是无法解决的,所以为了解决这个问题,需要下载apk文件升级APP.   1.配置文件如下:{'appVersion':'1.0.0', ...

  6. Spring应用教程-1

    作者:禅楼望月(http://www.cnblogs.com/yaoyinglong) Spring是Web框架,是容器框架,用于配置bean,并维护bean之间的关系的框架. 1. Spring在整 ...

  7. 100行JS实现HTML5的3D贪吃蛇游戏

    js1k.com收集了小于1k的javascript小例子,里面有很多很炫很酷的游戏和特效,今年规则又增加了新花样,传统的classic类型基础上又增加了WebGL类型,以及允许增加到2K的++类型, ...

  8. .Net 配置文件--继承ConfigurationSection实现自定义处理类处理自定义配置节点

    除了使用继承IConfigurationSectionHandler的方法定义处理自定义节点的类,还可以通过继承ConfigurationSection类实现同样效果. 首先说下.Net配置文件中一个 ...

  9. 使用Windows PE的U盘安装win7

    前年刚去公司的时候用PE装过好多系统,最近又装一台华硕的,碰到了一个问题,一起记录了下. 华硕X45,Bios已经改为U盘启动了,但就是进不去,因为知道可能还有个选磁盘启动项的键,找了半天原来按Esc ...

  10. 自定义动画方法animate

    animate的使用方法:animate(params,speed,callback); 例子:animate({ right: "-=600px",height:"+= ...