今天在计算collectionView存放最小间距的时候用到一函数 " ABS " 顺便就查了一下这些数学函数在代码中的使用..

//-----------------------函数在代码中使用-----------------------------

// 获得super已经计算好的布局属性

NSArray *array = [super layoutAttributesForElementsInRect:rect];

// 计算collectionView最中心点的x值

CGFloat centerX = proposedContentOffset.x + self.collectionView.frame.size.width * 0.5;

// 存放最小的间距值

CGFloat minDelta = MAXFLOAT;

for (UICollectionViewLayoutAttributes *attrs in array) {

if (ABS(minDelta) > ABS(attrs.center.x - centerX)) {

minDelta = attrs.center.x - centerX;

}

}

//-------------------sin cos的应用代码-----------------

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath

{

NSInteger count = [self.collectionView numberOfItemsInSection:0];

CGFloat radius = 70;

CGFloat oX = self.collectionView.frame.size.width * 0.5;

CGFloat oY = self.collectionView.frame.size.height * 0.5;

UICollectionViewLayoutAttributes *attrs = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];

attrs.size = CGSizeMake(50, 50);

if (count == 1) {

attrs.center = CGPointMake(oX, oY);

} else {

CGFloat angle = (2 * M_PI / count) * indexPath.item;

CGFloat centerX = oX + radius * sin(angle);

CGFloat centerY = oY + radius * cos(angle);

attrs.center = CGPointMake(centerX, centerY);

}

return attrs;

}

@end

//-------------------------------------------------------------------

rand() ----随机数

abs() / labs() ----整数绝对值

fabs() / fabsf() / fabsl() ----浮点数绝对值

floor() / floorf() / floorl() ----向下取整

ceil() / ceilf() / ceill() ----向上取整

round() / roundf() / roundl() ----四舍五入

sqrt() / sqrtf() / sqrtl() ----求平方根

fmax() / fmaxf() / fmaxl() ----求最大值

fmin() / fminf() / fminl() ----求最小值

hypot() / hypotf() / hypotl() ----求直角三角形斜边的长度

fmod() / fmodf() / fmodl() ----求两数整除后的余数

modf() / modff() / modfl() ----浮点数分解为整数和小数

frexp() / frexpf() / frexpl() ----浮点数分解尾数和二为底的指数

sin() / sinf() / sinl() ----求正弦值

sinh() / sinhf() / sinhl() ----求双曲正弦值

cos() / cosf() / cosl() ----求余弦值

cosh() / coshf() / coshl() ----求双曲余弦值

tan() / tanf() / tanl() ----求正切值

tanh() / tanhf() / tanhl() ----求双曲正切值

asin() / asinf() / asinl() ----求反正弦值

asinh() / asinhf() / asinhl() ----求反双曲正弦值

acos() / acosf() / acosl() ----求反余弦值

acosh() / acoshf() / acoshl() ----求反双曲余弦值

atan() / atanf() / atanl() ----求反正切值

atan2() / atan2f() / atan2l() ----求坐标值的反正切值

atanh() / atanhf() / atanhl() ----求反双曲正切值

ios开发函数(数学函数应用)的更多相关文章

  1. iOS math.h数学函数

    在实际工作中有些程序不可避免的需要使用数学函数进行计算,比如地图程序的地理坐标到地图坐标的变换.Objective-C做为ANSI C的扩展,使用C标准库头文件<math.h>中定义的数学 ...

  2. iOS开发之----常用函数和常数

    介绍一下Objective-c常用的函数,常数变量 算术函数 [算术函数] 函数名 说明 int rand() 随机数生成.(例)srand(time(nil)); //随机数初期化int val = ...

  3. javascript函数一共可分为五类: ·常规函数 ·数组函数 ·日期函数 ·数学函数 ·字符串函数

    javascript函数一共可分为五类:    ·常规函数    ·数组函数    ·日期函数    ·数学函数    ·字符串函数    1.常规函数    javascript常规函数包括以下9个 ...

  4. Delphi 常用函数(数学函数)round、trunc、ceil和floor

    源:Delphi 常用函数(数学函数)round.trunc.ceil和floor Delphi 常用函数(数学) Delphi中怎么将实数取整? floor 和 ceil 是 math unit 里 ...

  5. php常用函数——数学函数

    php常用函数——数学函数

  6. VB.NET函数——数学函数/字母串函数

    一.数学函数 函数 说明 Abs (num) 取绝对值. Exp (num) 返回以e为底.以num为指数的值,如Exp(2)返回e^2值. Log (num) 返回参数num的自然对数值,为Doub ...

  7. MySql常用函数数学函数、加密函数等(转—收藏)

        MySql函数众多,这里只是列举了一部分常用的函数.   一.数学函数 ABS(x)                                         // 返回x的绝对值 BI ...

  8. sql server 系统常用函数:聚合函数 数学函数 字符串函数 日期和时间函数和自定义函数

    一.系统函数 1.聚合函数 聚合函数常用于GROUP BY子句,在SQL Server 2008提供的所有聚合函数中,除了COUNT函数以外,聚合函数都会忽略空值AVG.COUNT.COUNT_BIG ...

  9. MySQL 进阶4 SQL常见函数: 字符函数/数学函数/日期函数/流程控制函数(if/case)

    # 进阶4 SQL常见函数 分类: 1/单行函数: 字符函数: concat(),length(),ifnull(__,default) ,instr(), trim(),upper(),lower( ...

随机推荐

  1. JQuery-EasyUI DataGrid CRUD

    ASP.NET使用EasyUI-DataGrid + ashx + JQuery Ajax:实现数据的增删查改,查询和分页! 数据表: 学生表:学生编号.姓名.性别.班级编号.年龄 班级表:班级编号. ...

  2. SQL双重游标(双重循环)--笔记

    declare )='', )='', )='' --创建游标 declare @cursor cursor --设定游标欲操作的数据集 set @cursor=cursor for select s ...

  3. FineUI第十五天---表格概述

    Grid表格概述  跟Asp.Net的差不多. 下面介绍一些属性:  ExpandUnusedSpace:此列充满所有的剩余空间,并且随着表格宽度变化而变化 DataToolTipField:用来显示 ...

  4. Attempt to present <vc> on <vc> which is already presenting <vc>/(null)

    在给 tableViewCell 添加长按手势弹出一个 popViewController 的时候,遇到的这个变态问题: Warning: Attempt to present <UINavig ...

  5. sublime text3 package control 安装

    1.安装 package control 按快捷键ctrl+` 或使用菜单 View->Show Console 打开控制台,然后粘贴如下安装代码 import urllib.request,o ...

  6. 51Nod 1378 夹克老爷的愤怒

    Description 一棵树,可以进行染色,被染色的点可以控制与它距离不超过 \(k\) 的所有点,问控制整棵树最少需要染几个点. Sol 贪心. 记录一下最深的未染色点和最浅的染色点,判断一下能否 ...

  7. innerHtml innerText textContent兼容性问题

    innerHtml,innerText,textContentinnerHtml获取元素带标签的内容:innerText只获取元素的文本:火狐不支持innerText,支持textContent: / ...

  8. 转:bwa的使用方法

    bwa的使用需要两中输入文件:    Reference genome data(fasta格式 .fa, .fasta, .fna)    Short reads data (fastaq格式 .f ...

  9. Python super继承详解

    MRO(Method resolution order)是python用来解析方法调用顺序的,mro中记录了一个类的所有基类的类类型序列,super不是简单地调用基类的方法,而是按照MRO中的顺序来调 ...

  10. sed使用的并不是完全的正则表达式

    经过实验发现,命令sed 's/pattern/replacement/' file中,pattern使用的并不是完全的正则表达式,而如果想使用正则表达式,需要使用sed命令的 -r 选项: sed ...