1:view中的clipsTobounds属性

  1. iew2添加view1到中,如果view2大于view1,或者view2的坐标不全在view1的范围内,view2是盖着view1的,意思就是超出的部份也会画出来,UIView有一个属性,clipsTobounds 默认情况下是NO。如果,我们想要view2把超出的那部份隐藏起来的话,就得改变它的父视图也就view1clipsTobounds属性值。view1.clipsTobounds = YES;
  2. 可以很好地解决覆盖的问题

2:UIScrollView滚动视图加载单元格点击事件

  1. svView = [[UIScrollView alloc] initWithFrame:CGRectMake(, , mainWidth, perHeight)];
  2. svView.bounces = NO;
  3. svView.contentSize = CGSizeMake(perWidth*, perHeight);
  4. UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
  5. [self addGestureRecognizer:tap];
  6. [self addSubview:svView];
  7.  
  8. 事件:
  9.  
  10. - (void)tapClick:(UITapGestureRecognizer*)tap
  11. {
  12. CGPoint point = [tap locationInView:svView];
  13. int page = point.x / perWidth;
  14. HomeHostest* hot = [myData objectAtIndex:page];
  15. if(delegate)
  16. {
  17. [delegate adClick:[NSString stringWithFormat:@"goodsdetail,%@",[hot.goodsID stringValue]]];
  18. }
  19. }
  20.  
  21. - (CGPoint)locationInView:(UIView *)view:函数返回一个CGPoint类型的值,表示触摸在view这个视图上的位置,这里返回的位置是针对view的坐标系的。调用时传入的view参数为空的话,返回的时触摸点在整个窗口的位置。
  22.  
  23. (CGPoint)previousLocationInView:(UIView *)view:该方法记录了前一个坐标值,函数返回也是一个CGPoint类型的值, 表示触摸在view这个视图上的位置,这里返回的位置是针对view的坐标系的。调用时传入的view参数为空的话,返回的时触摸点在整个窗口的位置。

3:对表格中的某个节跟每一行进行单独刷新

  1. [self.myTableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow: inSection:]] withRowAnimation:UITableViewRowAnimationAutomatic];

4:类似微信的搜索附近的人的功能 在 服务端的实现 

  1. 基准线预先计算法
  2. 每个用户在服务器端都会保留最后的经度j1 和纬度w1 的同时 保留对经度基准线的相对距离 dj1 和纬度基准线的相对距离 dw1
  3. 经度基准线可以是中国最东边的经度 纬度基准线可以是中国最北边的纬度
  4.  
  5. 当前用户对经度基准线的相对距离 dj2 =230km 和纬度基准线的相对距离 dw2=350km
  6. 查找时sql语句可以这么写(.5公里内的用户)
  7. select * from user where dj1>(-1.5) and dj1<(+1.5) and dw1>(-1.5) and dw1<(+1.5)
  8. 相当于获得当前用户 周围正方形1.5公里区域的用户
  9.  
  10. 此外通过将冷热数据分开存放及 分块存放 用户地理数据应该能有效的提高查询速度
  11. 另附:(考虑把经度和纬度分成多个表存放,比如24个经度表,每个表按纬度分别排序,查找时只在最靠近的那个表查找,由于是排序的所以并不需要遍历每个记录,比如纬度相差多少的就不用再找了。

5:定位一些基础内容 CLLocation

  1. . CLLocation
  2. --------------------------------------------------------
  3. CLLocationManager 定位管理者
  4. CLLocation 代表位置(经度/纬度/高度/速度/路线等)
  5. CLHeading 代表移动方向
  6. CLRegion 代表一个区域
  7. >CLCircularRegion 圆形区域
  8. >CLBeaconRegion 蓝牙信号区域
  9.  
  10. 返回定位服务是否可用
  11. [CLLocationManager locationServicesEnabled];
  12. 返回延迟定位更新是否可用
  13. [CLLocationManager deferredLocationUpdatesAvailable];
  14. 返回重大位置改变监听是否可用
  15. [CLLocationManager significantLocationChangeMonitoringAvailable];
  16. 返回是否支持磁力计算方向
  17. [CLLocationManager headingAvailable];
  18. 返回蓝牙信号范围服务是否可用
  19. [CLLocationManager isRangingAvailable];
  20.  
  21. --------------------------------------------------------
  22. 设置是否可以暂停定位来节省电池电量, YES不需要定位数据时自动暂停定位
  23. // mgr.pausesLocationUpdatesAutomatically
  24.  
  25. --------------------------------------------------------
  26. 每隔多少米定位一次, 只有水平方向超过该值时才会重新定位
  27. // mgr.distanceFilter = 100;
  28.  
  29. --------------------------------------------------------
  30. 定位精确度
  31. // mgr.desiredAccuracy;
  32. kCLDistanceFilterNone;
  33. kCLLocationAccuracyBestForNavigation 导航级最佳精准
  34. kCLLocationAccuracyBest; 最佳精准
  35. kCLLocationAccuracyNearestTenMeters; 10米误差
  36. kCLLocationAccuracyHundredMeters; 百米胡茬
  37. kCLLocationAccuracyKilometer; 千米误差
  38. kCLLocationAccuracyThreeKilometers; 3千米误差
  39.  
  40. --------------------------------------------------------
  41. 定位数据的用途
  42. // mgr.activityType;
  43. CLActivityTypeOther 作为普通用途
  44. CLActivityTypeAutomotiveNavigation 作为车辆导航
  45. CLActivityTypeFitness 作为步行
  46. CLActivityTypeOtherNavigation 作为其它导航
  47.  
  48. --------------------------------------------------------
  49. // CLLocation
  50. location.coordinate; 坐标, 包含经纬度
  51. location.altitude; 设备海拔高度 单位是米
  52. location.course; 设置前进方向 0表示北 90 180 270西
  53. location.horizontalAccuracy; 水平精准度
  54. location.verticalAccuracy; 垂直精准度
  55. location.timestamp; 定位信息返回的时间
  56. location.speed; 设备移动速度 单位是米/秒, 适用于行车速度而不太适用于步行
  57. /*
  58. 可以设置模拟器模拟速度
  59. bicycle ride 骑车移动
  60. run 跑动
  61. freeway drive 高速公路驾车
  62. */
  63.  
  64. --------------------------------------------------------
  65. // CLAuthorizationStatus
  66. 用户从未选择过权限
  67. kCLAuthorizationStatusNotDetermined
  68. 无法使用定位服务,该状态用户无法改变
  69. kCLAuthorizationStatusRestricted
  70. 用户拒绝该应用使用定位服务,或是定位服务总开关处于关闭状态
  71. kCLAuthorizationStatusDenied
  72. 已经授权(废弃)
  73. kCLAuthorizationStatusAuthorized
  74. 用户允许该程序无论何时都可以使用地理信息
  75. kCLAuthorizationStatusAuthorizedAlways
  76. 用户同意程序在可见时使用地理位置
  77. kCLAuthorizationStatusAuthorizedWhenInUse
  78.  
  79. --------------------------------------------------------
  80. // 计算两个位置之间的距离, 单位是米
  81. [newLocation distanceFromLocation:self.prevLocation];
  82.  
  83. --------------------------------------------------------
  84. 获取方向信息不会提示用户(不需要授权), 因为不会泄露隐私
  85. // [self.mgr startUpdatingHeading];
  86.  
  87. magneticHeading 设备与磁北的相对角度
  88. trueHeading 设置与真北的相对角度, 必须和定位一起使用, iOS需要设置的位置来计算真北
  89. 真北始终指向地理北极点
  90. 磁北对应随着时间变化的地球磁场北极
  91.  
  92. // 牛逼的地方
  93. 116.958776,36.721199
  94.  
  95. --------------------------------------------------------
  96. // 错误:使用CoreLocation获取地理位置信息,报错
  97. Error Domain=kCLErrorDomain Code= "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
  98.  
  99. 解决方法:
  100. .确定模拟器(手机)已经联网并且允许程序获取地理位置
  101. .重置地理位置服务或者网络服务
  102.  
  103. PS:如果是模拟器就果断直接重置模拟器吧 IOS Simulator - Reset Content and Settings..。
  104.  
  105. /*
  106. 注意: iOS7只要开始定位, 系统就会自动要求用户对你的应用程序授权. 但是从iOS8开始, 想要定位必须先"自己""主动"要求用户授权
  107. 在iOS8中不仅仅要主动请求授权, 而且必须再info.plist文件中配置一项属性才能弹出授权窗口
  108. NSLocationWhenInUseDescription,允许在前台获取GPS的描述
  109. NSLocationAlwaysUsageDescription,允许在后台获取GPS的描述
  110. */

6:CGPoint一些常见操作

  1. 数据结构中的一个点CGPoint代表在一个二维坐标系统。数据结构的位置和尺寸CGRect代表的一个长方形。数据结构的尺寸CGSize代表宽度和高度。
  2.  
  3. 、创建一个几何原始数值
  4. CGPoint CGPointMakeCGPoint A,CGPoint B
  5. 返回一个指定坐标点
  6. CGRect CGRectMakeCGFloat x,CGFloat y,CGFloat width,CGFloat height
  7. 根据指定的坐标和大小创建一个矩形
  8. CGSize CGSizeMakeCGFloat width,CGFloat height
  9. 根据指定长宽创建一个CGSize
  10. 、修改矩形
  11. CGRectDivide
  12. CGRect CGRectInsetCGRect rect,CGFloat dx,CGFloat dy
  13. 返回一个比原矩形大或小的矩形,但是中心点是相同的
  14. CGRect CGRectIntegralCGRect A
  15. 将矩形A的值转变成整数,得到一个最小的矩形,
  16. CGRect CGRectIntersection:(CGRect ACGRect B
  17. 获取两个矩形相交处所的矩形,没有相交返回NULL,用CGRectIsNull来检测
  18. CGRectOffset
  19. CGRectStandardize
  20. CGRectUnion
  21. 、比较数值
  22. bool CGPointEqualToPointCGPoint A,CGPoint B
  23. 返回两个点是否相等
  24. bool CGSizeEqualToSizeCGSize ACGSize B
  25. CGSizeAB是否相等
  26. bool CGRectEqualToRectCGRect ACGRect B
  27. 矩形AB的位置大小是否相等
  28. bool CGRectIntersectsRectCGRect ACGRect B
  29. 矩形AB是否相交,可用来判断精灵是否离开了屏幕
  30. 、检查
  31. bool CGRectContainsPointCGRect A, CGPoint B
  32. 检测矩形A是否包含指定的点B
  33. bool CGRectContainsRectCGRect ACGRect B
  34. 检测矩形A是否包含矩形B
  35. 、获取最大值、中等职和最小值
  36. CGFloat CGRectGetMinXCGRect A
  37. 获取矩形x坐标的最小值
  38. CGFloat CGRectGetMinYCGRect A
  39. 获取矩形y坐标的最小值
  40. CGFloat CGRectGetMidXCGRect A
  41. 获取矩形x坐标的中间值
  42. CGFloat CGRectGetMidYCGRect A
  43. 获取矩形y坐标的中间值
  44. CGFloat CGRectGetMaxXCGRect A
  45. 获取矩形x坐标的最大值
  46. CGFloat CGRectGetMaxYCGRect A
  47. 获取矩形y坐标的最大值
  48. 、获取高和宽
  49. CGFloat CGRectGetHeightCGRect A
  50. 获取矩形A的高
  51. CGFloat CGRectGetWidthCGRect A
  52. 获取矩形A的宽
  53. 、检测矩形是否存在或是无穷大
  54. bool CGRectIsEmptyCGRect A
  55. 矩形A是否长和宽都是0,或者是个NULL
  56. bool CGRectIsNullCGRect A
  57. 矩形A是否为NULL
  58. bool CGRectIsInfiniteCGRect A
  59. 矩形A是否无穷大,没有边界

7:iOS7 中 boundingRectWithSize:options:attributes:context:计算文本尺寸的使用

  1. 之前使用了NSString类的sizeWithFont:constrainedToSize:lineBreakMode:方法,但是该方法已经被iOS7 Deprecated了,而iOS7新出了一个boudingRectWithSize:options:attributes:context方法来代替。
  2.  
  3. 而具体怎么使用呢,尤其那个attribute
  4.  
  5. NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:]};
  6. CGSize size = [@“相关NSString boundingRectWithSize:CGSizeMake(, ) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
  7.  
  8. 属性
  9.  
  10. a:NSStringDrawingTruncatesLastVisibleLine
  11.  
  12. 如果文本内容超出指定的矩形限制,文本将被截去并在最后一个字符后加上省略号。如果没有指定NSStringDrawingUsesLineFragmentOrigin选项,则该选项被忽略。
  13.  
  14. b:NSStringDrawingUsesLineFragmentOrigin
  15.  
  16. 绘制文本时使用 line fragement origin 而不是 baseline origin
  17.  
  18. c:NSStringDrawingUsesFontLeading
  19.  
  20. 计算行高时使用行距。(译者注:字体大小+行间距=行距)
  21.  
  22. d:NSStringDrawingUsesDeviceMetrics
  23.  
  24. 计算布局时使用图元字形(而不是印刷字体)。
  25.  
  26. 实例二:
  27. NSString *str = @"正在搜索附近的位置";
  28. UIFont *font = [UIFont systemFontOfSize:14.0];
  29. CGSize size = CGSizeMake(CGFLOAT_MAX, );
  30. CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:font.fontName size:font.pointSize]} context:nil];
  31.  
  32. CGRect buttonFrame = CGRectZero;
  33. buttonFrame.size.height = CGRectGetHeight(rect);
  34. buttonFrame.size.width = CGRectGetWidth(rect);
  35.  
  36. UILabel *label = [[UILabel alloc]initWithFrame:buttonFrame];

8:一段布局排版关于tableView.tableFooterView设置按键跟等待提示

  1. - (UIView *)searchDisplayLoadingFooterView
  2. {
  3. if (!_searchDisplayLoadingFooterView) {
  4. _searchDisplayLoadingFooterView = [[UIView alloc]initWithFrame:CGRectMake(, , CGRectGetWidth(self.tableView.bounds), )];
  5. _searchDisplayLoadingFooterView.backgroundColor = [UIColor clearColor];
  6. NSString *str = @"正在搜索附近的位置";
  7. UIFont *font = [UIFont systemFontOfSize:14.0];
  8. CGSize size = CGSizeMake(CGFLOAT_MAX, );
  9. CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont fontWithName:font.fontName size:font.pointSize]} context:nil];
  10.  
  11. CGRect buttonFrame = CGRectZero;
  12. buttonFrame.size.height = CGRectGetHeight(rect);
  13. buttonFrame.size.width = CGRectGetWidth(rect);
  14.  
  15. UILabel *label = [[UILabel alloc]initWithFrame:buttonFrame];
  16. label.backgroundColor = [UIColor clearColor];
  17. label.text = str;
  18. label.font = font;
  19. label.textColor = [UIColor colorWithHexString:@"0x222222"];
  20. label.numberOfLines = ;
  21. label.textAlignment = NSTextAlignmentCenter;
  22. label.center = _searchDisplayLoadingFooterView.center;
  23. [_searchDisplayLoadingFooterView addSubview:label];
  24.  
  25. CGPoint indicatorCenter = CGPointZero;
  26. indicatorCenter.x = CGRectGetMinX(label.frame) - ;
  27. indicatorCenter.y = label.center.y;
  28.  
  29. UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  30. indicator.center = indicatorCenter;
  31. indicator.hidesWhenStopped = YES;
  32. [_searchDisplayLoadingFooterView addSubview:indicator];
  33. [indicator startAnimating];
  34.  
  35. CGRect lineFrame = _searchDisplayLoadingFooterView.bounds;
  36. lineFrame.size.height = 0.5;
  37.  
  38. UIView *topLine = [[UIView alloc]initWithFrame:lineFrame];
  39. topLine.backgroundColor = [UIColor colorWithHexString:@"0xdddddd"];
  40.  
  41. lineFrame.origin.y = CGRectGetMaxY(_searchDisplayLoadingFooterView.bounds) - 0.5;
  42. UIView *bottomLine = [[UIView alloc]initWithFrame:lineFrame];
  43. bottomLine.backgroundColor = [UIColor colorWithHexString:@"0xdddddd"];
  44.  
  45. [_searchDisplayLoadingFooterView addSubview:topLine];
  46. [_searchDisplayLoadingFooterView addSubview:bottomLine];
  47. }
  48.  
  49. return _searchDisplayLoadingFooterView;
  50. }

9:百度坐标跟火星坐标相互转换

  1. //百度转火星坐标
  2. + (CLLocationCoordinate2D )bdToGGEncrypt:(CLLocationCoordinate2D)coord
  3. {
  4. double x = coord.longitude - 0.0065, y = coord.latitude - 0.006;
  5. double z = sqrt(x * x + y * y) - 0.00002 * sin(y * M_PI);
  6. double theta = atan2(y, x) - 0.000003 * cos(x * M_PI);
  7. CLLocationCoordinate2D transformLocation ;
  8. transformLocation.longitude = z * cos(theta);
  9. transformLocation.latitude = z * sin(theta);
  10. return transformLocation;
  11. }
  12.  
  13. //火星坐标转百度坐标
  14. + (CLLocationCoordinate2D )ggToBDEncrypt:(CLLocationCoordinate2D)coord
  15. {
  16. double x = coord.longitude, y = coord.latitude;
  17.  
  18. double z = sqrt(x * x + y * y) + 0.00002 * sin(y * M_PI);
  19. double theta = atan2(y, x) + 0.000003 * cos(x * M_PI);
  20.  
  21. CLLocationCoordinate2D transformLocation ;
  22. transformLocation.longitude = z * cos(theta) + 0.0065;
  23. transformLocation.latitude = z * sin(theta) + 0.006;
  24.  
  25. return transformLocation;
  26. }

IOS开发基础知识--碎片20的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  3. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  4. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  5. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  6. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  7. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

随机推荐

  1. android帧动画,移动位置,缩放,改变透明度等动画讲解

    1.苦逼的需求又来了,需要实现一些动画效果,第一个想到的是播放gif图片,但是这样会占包的资源,并且清晰度不高,于是想着程序实现,自己用帧动画+缩放+移动+透明度 实现了一些想要的效果,这里跟大家分享 ...

  2. Java内存模型深度解析:重排序 --转

    原文地址:http://www.codeceo.com/article/java-memeory-2.html 数据依赖性 如果两个操作访问同一个变量,且这两个操作中有一个为写操作,此时这两个操作之间 ...

  3. grape动态PHP结构(三)——API接口

    一.app视图与控制器

  4. 关于Java中的final关键字

    Java中的final关键字是用来限制用户行为的,说白了,就是用来限制我们这些程序员的.final可以用来修饰:变量.方法.类. 1)Java final variable final用来修饰变量时, ...

  5. DotNet项目中的一些常用验证操作

    在项目中需要对用户输入的信息,以及一些方法生成的结果进行验证,一般在项目中较多的采用js插件或js来进行有关信息的校验,但是从项目安全性的角度进行考虑,可对系统进行js注入. 如果在后台对用户输入的信 ...

  6. 使用Jquery的Ajax实现无刷新更新,修改,删除页面

    本文将向大家讲述一下最近工作的一些总结,主要包括了以下内容,注册界面以及详细信息界面的编辑.主要是介绍了AJAX技术,因为我觉得其他方面没什么好介绍的.首先是跟大家说一下Ajax的优点,假如你删除了一 ...

  7. SSE指令集优化学习:双线性插值

    对SSE的学习总算迈出了第一步,用2天时间对双线性插值的代码进行了优化,现将实现的过程梳理以下,算是对这段学习的一个总结. 1. 什么是SSE 说到SSE,首先要弄清楚的一个概念是SIMD(单指令多数 ...

  8. SQL Server基础之游标

    查询语句可能返回多条记录,如果数据量非常大,需要使用游标来逐条读取查询结果集中的记录.应用程序可以根据需要滚动或浏览其中的数据.本篇介绍游标的概念.分类.以及基本操作等内容. 一:认识游标   游标是 ...

  9. phpcurl 请求Chunked-Encoded data 遇到的一个问题

    最早出现的问题情况是提供es的部门在es的外部封装了一个gateway做请求中转. 当我们转换到gateway上之后,发现了问题: 有的请求可以获取到数据,有的请求获取不到数据. 仔细分析了业务代码, ...

  10. 怎样使用My97日期控件

    有网友说无法使用My97日期控件,Insus.NET测试一下,是可以正常使用了. 在ASP.NET MVC环境中测试. 去官网下载My97日期控件程序包: 下载解压之后,把程序的目录拷贝至projec ...