点击return取消textView 的响应者

  1. - (BOOL)textFieldShouldReturn:(UITextField *)textField
  2. {
  3. [_contactTextFiled resignFirstResponder];
  4. return YES;
  5. }
  6. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
  7. if([text isEqualToString:@"\n"]){
  8. [textView resignFirstResponder];
  9. [_contactTextFiled becomeFirstResponder];
  10. return YES;
  11. }
  12. return YES;
  13. }

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

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

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

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

  1. [UIView setAnimationsEnabled:NO];
  2. [_listTable beginUpdates];
  3. [_listTable reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
  4. [_listTable endUpdates];
  5. [UIView setAnimationsEnabled:YES];

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

画出下列曲线:

  1. UIView *myCustomView = [[UIView alloc]initWithFrame:CGRectMake(0, 204,kScreenWidth, 120)];
  2. myCustomView.backgroundColor = [UIColor whiteColor];
  3. [view addSubview:myCustomView];
  4. UIBezierPath *bezierPath = [UIBezierPath bezierPath];
  5. [bezierPath moveToPoint:CGPointMake(0,0)];
  6. [bezierPath addCurveToPoint:CGPointMake(myCustomView.width, 0) controlPoint1:CGPointMake(0, 0) controlPoint2:CGPointMake(myCustomView.width/2, 40)];
  7. [bezierPath addLineToPoint:CGPointMake(myCustomView.width, myCustomView.height)];
  8. [bezierPath addLineToPoint:CGPointMake(0, myCustomView.height)];
  9. [bezierPath closePath];
  10. CAShapeLayer *shapLayer = [CAShapeLayer layer];
  11. shapLayer.path = bezierPath.CGPath;
  12. myCustomView.layer.mask = shapLayer;
  13. myCustomView.layer.masksToBounds = YES;

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

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

TabBar的隐藏与消失:

  1. - (void)hidesTabBar:(BOOL)hidden{
  2. [UIView beginAnimations:nil context:NULL];
  3. [UIView setAnimationDuration:0];
  4. for (UIView *view in self.tabBarController.view.subviews){
  5. if ([view isKindOfClass:[UITabBar class]]) {
  6. if (hidden) {
  7. [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
  8. }else{
  9. [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
  10. }
  11. }else{
  12. if([view isKindOfClass:NSClassFromString(@"UITransitionView")]){
  13. if (hidden){
  14. [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
  15. }else{
  16. [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
  17. }
  18. }
  19. }
  20. }
  21. [UIView commitAnimations];
  22. }

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

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

NSAttributedString 与NSString互转:

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

监控UITextField 变化:

  1. // 注册监听
  2. [[NSNotificationCenter defaultCenter]postNotificationName:UITextFieldTextDidChangeNotification object:nil];
  3. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeForKeyWord:) name:UITextFieldTextDidChangeNotification object:nil];
  4. // 监听_pageTextField.text变化
  5. - (void)changeForKeyWord:(NSNotification *)sender
  6. {
  7. [self checkNum:_pageTextField.text];
  8. }
  9. - (BOOL)checkNum:(NSString *)str
  10. {
  11. NSString *regex = @"^[0-9]+(.[0-9]{2})?$";
  12. NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
  13. BOOL isMatch = [pred evaluateWithObject:str];
  14. if (!isMatch && _pageTextField.text.length>0) {
  15. UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"页码只能输入数字哦" delegate:self cancelButtonTitle:@"重新输入" otherButtonTitles:nil, nil nil];
  16. alertView.delegate = self;
  17. [alertView show];
  18. return NO;
  19. }
  20. return YES;
  21. }

监听UITextField的点击事件

  1. [[NSNotificationCenter defaultCenter]postNotificationName:UITextFieldTextDidBeginEditingNotification object:nil];
  2. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(enterEdited:) name:UITextFieldTextDidBeginEditingNotification object:nil];
  3. - (void)enterEdited:(NSNotification *)sender
  4. {
  5. 事件写这里!希望帮到你!
  6. }

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

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

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

UITextField 边框样式及内容调整:

  1. //1. 设置的时候在ib里面记得选择无边框的,要不然随便你设置,都是无效的,也是坑死了。
  2. _textBoxName.layer.borderWidth=1.0f;
  3. _textBoxName.layer.borderColor=[UIColorcolorWithRed:0xbf/255.0fgreen:0xbf/255.0fblue:0xbf/255.0falpha:1].CGColor;
  4. //2.在uitextfield 中文字最左边距离左侧边框的距离
  5. _textBoxName.leftView=[[UIViewalloc] initWithFrame:CGRectMake(0,0, 16,51)];
  6. _textBoxName.leftViewMode=UITextFieldViewModeAlways;

图片旋转控制:

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

改变cell的选中颜色:

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

取整问题:

    1. Objective-C拓展了C,自然很多用法是和C一致的。比如浮点数转化成整数,就有以下四种情况。
    2. 1.简单粗暴,直接转化
    3. float f = 1.5; int a; a = (int)f; NSLog("a = %d",a);
    4. 输出结果是1。(int)是强制类型转化,丢弃浮点数的小数部分。
    5. 2.高斯函数,向下取整
    6. float f = 1.6; int a; a = floor(f); NSLog("a = %d",a);
    7. 输出结果是1。floor()方法是向下取整,类似于数学中的高斯函数 [].取得不大于浮点数的最大整数,对于正数来说是舍弃浮点数部分,对于复数来说,舍弃浮点数部分后再减1.
    8. 3.ceil函数,向上取整。
    9. float f = 1.5; int a; a = ceil(f); NSLog("a = %d",a);
    10. 输出结果是2。ceil()方法是向上取整,取得不小于浮点数的最小整数,对于正数来说是舍弃浮点数部分并加1,对于复数来说就是舍弃浮点数部分.
    11. 4.通过强制类型转换四舍五入。
    12. float f = 1.5; int a; a = (int)(f+0.5); NSLog("a = %d",a);

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

  1. iOS中 项目开发易错知识点总结 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博! 点击return取消textView 的响应者 - (BOOL)textFieldShouldReturn:(UI ...

  2. JavaScript易错知识点整理

    前言 本文是我学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由浅入深的介绍和讲解,其中也涉及了一 ...

  3. JavaScript 易错知识点整理

    本文是我学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由浅入深的介绍和讲解,其中也涉及了一些ES ...

  4. JavaScript易错知识点整理[转]

    前言 本文是我学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由浅入深的介绍和讲解,其中也涉及了一 ...

  5. JS易错知识点

    JAVASCRIPT易错知识点整理 前言 本文是学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由 ...

  6. Java易错知识点(1) - 关于ArrayList移除元素后剩下的元素会立即重排

    帮一个网友解答问题时,发现这样一个易错知识点,现总结如下: 1.易错点: ArrayList移除元素后,剩下的元素会立即重排,他的 size() 也会立即减小,在循环过程中容易出错.(拓展:延伸到所有 ...

  7. JavaScript易错知识点

    JavaScript易错知识点整理1.变量作用域上方的函数作用域中声明并赋值了a,且在console之上,所以遵循就近原则输出a等于2. 上方的函数作用域中虽然声明并赋值了a,但位于console之下 ...

  8. iOS中关于KVC与KVO知识点

    iOS中关于KVC与KVO知识点 iOS中关于KVC与KVO知识点  一.简介 KVC/KVO是观察者模式的一种实现,在Cocoa中是以被万物之源NSObject类实现的NSKeyValueCodin ...

  9. [置顶] 单片机C语言易错知识点经验笔记

    今天写这一篇文章并不是因为已经想好了一篇文章才写下来,而是我要将这一篇文章作为一个长期的笔记来写,我会一直更新.在进行单片机开发时,经常都会出现一些很不起眼的问题,这些问题其实都是很基础的c语言知识点 ...

随机推荐

  1. Python模块(pickle)

    pickle 序列化和反序列化 序列化作用 序列化使用 cPickle使用例 Python提供一个标准的模块,称为pickle.使用它你可以在一个文件中储存任何Python对象,之后你又可以把它完整无 ...

  2. javascript实例学习之四——javascript分页

    话不多少,直接上代码 html代码: <!DOCTYPE html> <html lang="en"> <head> <meta char ...

  3. ks使用lvm分区,ks启动

    part /boot -fstype ext3 -size= part swap -size= part pv. -size= -grow volgroup vg_root pv. logvol / ...

  4. sql语句查询出数据重复,取唯一数据

    select distinct mr.id,ifnull(mr.pid,0) as pid,mr.name from sys_role_res srr left join main_res mr on ...

  5. AWR--导出AWR数据

    SQL> create or replace directory expdp_dir as '/home/oracle/dump'; Directory created. SQL> @$O ...

  6. Java基础之一组有用的类——使用正则表达式搜索子字符串(TryRegex)

    控制台程序. 正则表达式只是一个字符串,描述了在其他字符串中搜索匹配的模式.但这不是被动地进行字符序列匹配,正则表达式其实是一个微型程序,用于一种特殊的计算机——状态机.状态机并不是真正的机器,而是软 ...

  7. Silverlight动画显示Line线

    目的:在silverlight中显示两点之间的连线,要求动画显示连线效果. 如果需实现动画效果不得不了解,Storyborad对象: Storyboard Silverlight   通过时间线控制动 ...

  8. PostgreSQL数据导出导入COPY

    [postgres@DELL-R720 bin]$ ./psql -p 6432psql (9.4.5)Type "help" for help. postgres=# postg ...

  9. 转:python webdriver API 之鼠标事件

    前面例子中我们已经学习到可以用 click()来模拟鼠标的单击操作,而我们在实际的 web 产品测试中 发现,有关鼠标的操作,不单单只有单击,有时候还要和到右击,双击,拖动等操作,这些操作包含在Act ...

  10. 对ImageView.ScaleType的详解

    设置的方式有两种: 1.在layout.xml里面定义android:scaleType = "center" 2.在代码中调用imageview.setScaleType(Ima ...