iOS中 项目开发易错知识点总结
点击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 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中 项目开发易错知识点总结的更多相关文章
- iOS中 项目开发易错知识点总结 韩俊强的博客
每日更新关注:http://weibo.com/hanjunqiang 新浪微博! 点击return取消textView 的响应者 - (BOOL)textFieldShouldReturn:(UI ...
- JavaScript易错知识点整理
前言 本文是我学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由浅入深的介绍和讲解,其中也涉及了一 ...
- JavaScript 易错知识点整理
本文是我学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由浅入深的介绍和讲解,其中也涉及了一些ES ...
- JavaScript易错知识点整理[转]
前言 本文是我学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由浅入深的介绍和讲解,其中也涉及了一 ...
- JS易错知识点
JAVASCRIPT易错知识点整理 前言 本文是学习JavaScript过程中收集与整理的一些易错知识点,将分别从变量作用域,类型比较,this指向,函数参数,闭包问题及对象拷贝与赋值这6个方面进行由 ...
- Java易错知识点(1) - 关于ArrayList移除元素后剩下的元素会立即重排
帮一个网友解答问题时,发现这样一个易错知识点,现总结如下: 1.易错点: ArrayList移除元素后,剩下的元素会立即重排,他的 size() 也会立即减小,在循环过程中容易出错.(拓展:延伸到所有 ...
- JavaScript易错知识点
JavaScript易错知识点整理1.变量作用域上方的函数作用域中声明并赋值了a,且在console之上,所以遵循就近原则输出a等于2. 上方的函数作用域中虽然声明并赋值了a,但位于console之下 ...
- iOS中关于KVC与KVO知识点
iOS中关于KVC与KVO知识点 iOS中关于KVC与KVO知识点 一.简介 KVC/KVO是观察者模式的一种实现,在Cocoa中是以被万物之源NSObject类实现的NSKeyValueCodin ...
- [置顶] 单片机C语言易错知识点经验笔记
今天写这一篇文章并不是因为已经想好了一篇文章才写下来,而是我要将这一篇文章作为一个长期的笔记来写,我会一直更新.在进行单片机开发时,经常都会出现一些很不起眼的问题,这些问题其实都是很基础的c语言知识点 ...
随机推荐
- 如何解决SQLServer占CPU100%
文章目录 遇到的问题 使用SQLServer Profiler监控数据库 SQL1:查找最新的30条告警事件 SQL2:获取当前的总报警记录数 有哪些SQL语句会导致CPU过高? 查看SQL的查询计划 ...
- 使用awk统计字段重复实践
awk awk是一种规格化文件的分析工具, 主要处理对象类似数据库导出的条目文本文件, 其中一行,就对应一个记录,每个记录包含若干个字段. 类似这种文本: [root@www ~]# last -n ...
- C# (事件触发)回调函数,完美处理各类疑难杂症!
每次写博客,第一句话都是这样的:程序员很苦逼,除了会写程序,还得会写博客! 废话说多了...... 嘿嘿:本篇标题为:C# (事件触发)回调函数,完美处理各类疑难杂症.个人理解如下:事件触发也就是触 ...
- java 笔记(4) —— java I/O 流、字节流、字符流
Java中使用流来处理程序的输入和输出操作,流是一个抽象的概念,封装了程序数据于输入输出设备交换的底层细节.JavaIO中又将流分为字节流和字符流,字节流主要用于处理诸如图像,音频视频等二进制格式数据 ...
- 学习OpenCV——Kalman滤波
背景: 卡尔曼滤波是一种高效率的递归滤波器(自回归滤波器), 它能够从一系列的不完全及包含噪声的测量中,估计动态系统的状态.卡尔曼滤波的一个典型实例是从一组有限的,包含噪声的,对物体位置的观察序列(可 ...
- UVa10023手动开大数平方算法
题目链接:UVa 10023 import java.math.BigInteger; import java.util.Scanner; public class Main { public sta ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
- Python学习总结9:目录操作方法汇总
os.getcwd():得到当前工作目录,即当前Python脚本工作的目录路径os.listdir():返回指定目录下的所有文件和目录名os.remove():函数用来删除一个文件os.removed ...
- Android--HTTP协议
1 package com.http.get; 2 3 import java.io.FileOutputStream; 4 import java.io.IOException; 5 import ...
- PHP V5.2 中的新增功能,第 1 部分: 使用新的内存管理器
PHP V5.2:开始 2006 年 11 月发布了 PHP V5.2,它包括许多新增功能和错误修正.它废止了 5.1 版并被推荐给所有 PHP V5 用户进行升级.我最喜欢的实验室环境 —— Win ...