今天在计算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. PHP array_multisort() 函数详解 及 二维数组排序(模拟数据表记录按字段排序)

    一.先看最简单的情况. 有两个数组: $arr1 = array(1, 9, 5); $arr2 = array(6, 2, 4); array_multisort($arr1, $arr2); pr ...

  2. APPCAN IDE中安装emmet插件

    1.首先打开APPCAN IDE 2.帮助(help)-安装新软件(install New sofaWare) 3.打开Install窗口,点击 Add,在Add Repository窗口中,Name ...

  3. centos安装

    转:http://www.cnblogs.com/Johness/archive/2012/12/03/2800126.html 在已经安装了Win7的系统下安装CentOS 注意:1.由于涉及到对硬 ...

  4. Unity手游之路<九>自动寻路Navmesh之高级主题

    http://blog.csdn.net/janeky/article/details/17492531 之前我们一起学习了如何使用Navmesh组件来实现最基本的角色自动寻路.今天我们再继续深入探索 ...

  5. Java WebClient 总结

    private WebClient getAWebClient() { WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24); ...

  6. MySQL使用详解--根据个人学习总结

    1.安装配置 2.启动mysql服务并配置 mysql> \s(status也行) 查看当前服务器状态 查看编码状态 Server characterset : utf8 Db characte ...

  7. python 模块之间的变量共享

    才疏学浅,只知道两种方式: 1. 通过__builtin__实现: builtin1.py import __builtin__ __builtin__.some_global_var_among_m ...

  8. C#之GDI+

    1.使用Brushes填充矩形区域 Graphics g = e.Graphics; g.FillRectangle(Brushes.Green, , , , )); 2.使用LinearGradie ...

  9. Python之多线程

    廖雪峰教程--- http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683 ...

  10. iOS cannot find folder xcdatamodeld Xcode 7

    今天升级xcode7时发现了个这个编译bug,说是找不到xcdatamodeld. 解决方法如下: I had the same problem. Here are the steps I used ...