每日更新关注:http://weibo.com/hanjunqiang 
新浪微博!

点击return取消textView 的响应者

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [_contactTextFiled resignFirstResponder];
    return YES;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

    if([text isEqualToString:@"\n"]){

        [textView resignFirstResponder];
        [_contactTextFiled becomeFirstResponder];
        return YES;
    }
    return YES;
}

iOS一行代码将所有子视图从父视图上移除

这里主要利用了一个makeObjectsPerformSelector:函数。这个函数可以在很多场景下使用从而简化代码。

[xxxView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

有效解决刷新单个cell或者section闪一下的问题:

        [UIView setAnimationsEnabled:NO];
        [_listTable beginUpdates];
        [_listTable reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
        [_listTable endUpdates];
        [UIView setAnimationsEnabled:YES];

每日更新关注:http://weibo.com/hanjunqiang 
新浪微博!

画出下列曲线:

    UIView *myCustomView = [[UIView alloc]initWithFrame:CGRectMake(0, 204,kScreenWidth, 120)];
    myCustomView.backgroundColor = [UIColor whiteColor];
    [view addSubview:myCustomView];

    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    [bezierPath moveToPoint:CGPointMake(0,0)];
    [bezierPath addCurveToPoint:CGPointMake(myCustomView.width, 0) controlPoint1:CGPointMake(0, 0) controlPoint2:CGPointMake(myCustomView.width/2, 40)];
    [bezierPath addLineToPoint:CGPointMake(myCustomView.width, myCustomView.height)];
    [bezierPath addLineToPoint:CGPointMake(0, myCustomView.height)];
    [bezierPath closePath];

    CAShapeLayer *shapLayer = [CAShapeLayer layer];
    shapLayer.path = bezierPath.CGPath;
    myCustomView.layer.mask = shapLayer;
    myCustomView.layer.masksToBounds = YES;

当你使用 UISearchController 在 UITableView 中实现搜索条,在搜索框已经激活并推入新的 VC 的时候会发生搜索框重叠的情况:那就是 definesPresentationContext 这个布尔值!

每日更新关注:http://weibo.com/hanjunqiang 
新浪微博!

TabBar的隐藏与消失:

- (void)hidesTabBar:(BOOL)hidden{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];

    for (UIView *view in self.tabBarController.view.subviews){

        if ([view isKindOfClass:[UITabBar class]]) {
            if (hidden) {
                [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
            }else{
                [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
            }
        }else{
            if([view isKindOfClass:NSClassFromString(@"UITransitionView")]){
                if (hidden){
                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
                }else{

                    [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
                }
            }
        }
    }
    [UIView commitAnimations];
}

获取cell上按钮所在分区和行数:

    UIView *view = [sender superview]; // 获取父视图的view
    GCCollectGroupCellTableViewCell *cell = (GCCollectGroupCellTableViewCell*)[view superview]; // 获取cell
    NSIndexPath *indexPath = [_listTable indexPathForCell:cell]; // 获取cell对应的分区
    NSLog(@"%@",detailArr[indexPath.section-1][indexPath.row][@"comname"]);

NSAttributedString 与NSString互转:

    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[_CompanyFileds.comname dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    _CompanyFileds.comname = attrStr.string;

监控UITextField 变化:

// 注册监听
    [[NSNotificationCenter defaultCenter]postNotificationName:UITextFieldTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeForKeyWord:) name:UITextFieldTextDidChangeNotification object:nil];

// 监听_pageTextField.text变化
- (void)changeForKeyWord:(NSNotification *)sender
{
    [self checkNum:_pageTextField.text];
}
- (BOOL)checkNum:(NSString *)str
{
    NSString *regex = @"^[0-9]+(.[0-9]{2})?$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    BOOL isMatch = [pred evaluateWithObject:str];
    if (!isMatch && _pageTextField.text.length>0) {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"页码只能输入数字哦" delegate:self cancelButtonTitle:@"重新输入" otherButtonTitles:nil, nil];
        alertView.delegate = self;
        [alertView show];
        return NO;
    }
    return YES;
}

监听UITextField的点击事件

[[NSNotificationCenter defaultCenter]postNotificationName:UITextFieldTextDidBeginEditingNotification object:nil];
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(enterEdited:) name:UITextFieldTextDidBeginEditingNotification object:nil]; 

- (void)enterEdited:(NSNotification *)sender
{
    事件写这里!希望帮到你!
} 

每日更新关注:http://weibo.com/hanjunqiang 
新浪微博!

解决添加到父视图手势影响子视图手势的解决办法:(手势冲突)

//方法一:
#pragma mark--UIGestureRecognizerDelegate
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if([touch.view isKindOfClass:[UIButton class]]||[touch.view isKindOfClass:[UITableViewCell class]]||[touch.view isKindOfClass:[UITextField class]]||[touch.view isKindOfClass:[UITextView class]])
    {
        return NO;
    }
    return YES;
}
//方法二:
//UIView的exclusiveTouch属性
//通过设置[self setExclusiveTouch:YES];可以达到同一界面上多个控件接受事件时的排他性,从而避免一些问题。

UITextField 边框样式及内容调整:

//1. 设置的时候在ib里面记得选择无边框的,要不然随便你设置,都是无效的,也是坑死了。
  _textBoxName.layer.borderWidth=1.0f;
    _textBoxName.layer.borderColor=[UIColorcolorWithRed:0xbf/255.0fgreen:0xbf/255.0fblue:0xbf/255.0falpha:1].CGColor;

   //2.在uitextfield 中文字最左边距离左侧边框的距离
    _textBoxName.leftView=[[UIViewalloc] initWithFrame:CGRectMake(0,0, 16,51)];
    _textBoxName.leftViewMode=UITextFieldViewModeAlways;

图片旋转控制:

#pragma mark ----- 更新按钮动画
- (void)rotate360DegreeWithImageViews:(UIImageView *)myViews{
    CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 ];
    rotationAnimation.duration = 1.0;
    rotationAnimation.cumulative = YES;rotate360DegreeWithImageViews
    rotationAnimation.repeatCount = 100000;
    [myViews.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
[myViews.layer removeAllAnimations]; // 停止

改变cell的选中颜色:

cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = COLOR_BACKGROUNDVIEW;
不需要任何颜色可以这么设置:
cell.selectionStyle = UITableViewCellSelectionStyleNone;

取整问题:

Objective-C拓展了C,自然很多用法是和C一致的。比如浮点数转化成整数,就有以下四种情况。
1.简单粗暴,直接转化

float f = 1.5; int a; a = (int)f; NSLog("a = %d",a);
输出结果是1。(int)是强制类型转化,丢弃浮点数的小数部分。

2.高斯函数,向下取整

float f = 1.6; int a; a = floor(f); NSLog("a = %d",a);
输出结果是1。floor()方法是向下取整,类似于数学中的高斯函数 [].取得不大于浮点数的最大整数,对于正数来说是舍弃浮点数部分,对于复数来说,舍弃浮点数部分后再减1.

3.ceil函数,向上取整。

float f = 1.5; int a; a = ceil(f); NSLog("a = %d",a);
输出结果是2。ceil()方法是向上取整,取得不小于浮点数的最小整数,对于正数来说是舍弃浮点数部分并加1,对于复数来说就是舍弃浮点数部分.

4.通过强制类型转换四舍五入。

float f = 1.5; int a; a = (int)(f+0.5); NSLog("a = %d",a);

iOS开发者交流QQ群: 446310206  欢迎加入!

每日更新关注:http://weibo.com/hanjunqiang 
新浪微博!

iOS中 项目开发易错知识点总结 韩俊强的博客的更多相关文章

  1. iOS中 项目开发易错知识点总结

    点击return取消textView 的响应者 - (BOOL)textFieldShouldReturn:(UITextField *)textField { [_contactTextFiled  ...

  2. iOS中 支付宝钱包详解/第三方支付 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博! iOS开发者交流QQ群: 446310206 一.在app中成功完成支付宝支付的过程 1.申请支付宝钱包.参考网址 ...

  3. iOS中 支付宝钱包具体解释/第三方支付 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博! iOS开发人员交流QQ群: 446310206 一.在app中成功完毕支付宝支付的过程 1.申请支付宝钱包.參考网 ...

  4. iOS中发送短信/发送邮件的实现 韩俊强的博客

    需要引入框架: MessageUI.framework 布局如下: 短信和邮件: #import "ViewController.h" #import <MessageUI/ ...

  5. iOS开发中的零碎知识点笔记 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博 1.关联 objc_setAssociatedObject关联是指把两个对象相互关联起来,使得其中的一个对象作为另外 ...

  6. HTML5中 HTML列表/块/布局 韩俊强的博客

    从简单到复杂HTML5详解:每日更新关注:http://weibo.com/hanjunqiang  新浪微博! 1.HTML列表 1.有序 2.无序 3.有序star属性 4.有序无序列表 代码: ...

  7. iOS中 HTTP/Socket/TCP/IP通信协议具体解释 韩俊强的博客

    简介: // OSI(开放式系统互联), 由ISO(国际化标准组织)制定 // 1. 应用层 // 2. 表示层 // 3. 会话层 // 4. 传输层 // 5. 网络层 // 6. 数据链接层 / ...

  8. iOS中 扫描二维码/生成二维码具体解释 韩俊强的博客

    近期大家总是问我有没有关于二维码的demo,为了满足大家的需求,特此研究了一番,希望能帮到大家! 每日更新关注:http://weibo.com/hanjunqiang  新浪微博 指示根视图: se ...

  9. iOS中 扫描二维码/生成二维码详解 韩俊强的博客

    最近大家总是问我有没有关于二维码的demo,为了满足大家的需求,特此研究了一番,希望能帮到大家! 每日更新关注:http://weibo.com/hanjunqiang  新浪微博 指示根视图: se ...

随机推荐

  1. ●BZOJ 3545 [ONTAK2010]Peaks(离线)

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=3545 http://www.lydsy.com/JudgeOnline/problem.ph ...

  2. [bzoj5016][Snoi2017]一个简单的询问

    来自FallDream的博客,未经允许,请勿转载,谢谢. 给你一个长度为N的序列ai,1≤i≤N和q组询问,每组询问读入l1,r1,l2,r2,需输出   get(l,r,x)表示计算区间[l,r]中 ...

  3. Object 类

  4. JAVAEE——BOS物流项目10:权限概述、常见的权限控制方式、apache shiro框架简介、基于shiro框架进行认证操作

    1 学习计划 1.演示权限demo 2.权限概述 n 认证 n 授权 3.常见的权限控制方式 n url拦截权限控制 n 方法注解权限控制 4.创建权限数据模型 n 权限表 n 角色表 n 用户表 n ...

  5. 脱离文档流两操作,float和position:absolute的区别

    文档流:将窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素,块状元素独占一行,内联元素不独占一行: CSS中脱离文档流,也就是将元素从普通的布局排版中拿走,其他盒子在定位的时候,会当做脱离 ...

  6. spark升级后 集成hbase-1.0.0-cdh5.4.5异常

    .具体场景如下: spark1.6  升级  spark2.2 后    分析查询hbase  数据报异常: 具体错误如下:       ERROR TableInputFormat: java.io ...

  7. redis的数据持久化方案

    Redis的持久化方案有两种 1.Rdb方式:快照形式,定期将内存中的数据持久化到硬盘.是Redis默认的数据持久化的形式. Rdb:缺点是:数据还没有更新到磁盘上,突然断电,造成数据的不完整性. 在 ...

  8. PHP MySQL Delete

    DELETE 语句用于从数据库表中删除行. 删除数据库中的数据 DELETE FROM 语句用于从数据库表中删除记录. 语法 DELETE FROM table_name WHERE some_col ...

  9. [Gradle系列]Gradle打包apk多版本,多渠道,多环境,多功能,多模块随心所欲

    Tamic: http://blog.csdn.net/sk719887916/article/details/53411771 开始 上篇Gradle发布Module(Maven)到jcenter, ...

  10. 计算机网络之套接字SOCKET

    当某个应用进程启动系统调用时,控制权就从应用进程传递给了系统调用接口. 此接口再将控制权传递给计算机的操作系统.操作系统将此调用转给某个内部过程,并执行所请求的操作. 内部过程一旦执行完毕,控制权就又 ...