一、ceilf、ceil、ceill各种取整方式
extern float ceilf(float);
extern double ceil(double);
extern long double ceill(long double);
extern float floorf(float);
extern double floor(double);
extern long double floorl(longdouble);
extern float roundf(float);
extern double round(double);
extern long double roundl(long double);
round 如果参数是小数,则求本身的四舍五入.
ceil 如果参数是小数,则求最小的整数但不小于本身.
floor 如果参数是小数,则求最大的整数但不大于本身.
Example:如何值是3.4的话,则
-- round 3.000000
-- ceil 4.000000
-- floor 3.00000
int abs(int i); // 处理int类型的取绝对值
double fabs(double i); //处理double类型的取绝对值
float fabsf(float i); /处理float类型的取绝对值
二、处理UITableView、UICollectionView在iOS11中出现的暴走问题
查阅发现 iOS11弃用了automaticallyAdjustsScrollViewInsets属性,新增contentInsetAdjustmentBehavior来替代它
关于contentInsetAdjustmentBehavior:
typedef NS_ENUM(NSInteger, UIScrollViewContentInsetAdjustmentBehavior) {
UIScrollViewContentInsetAdjustmentAutomatic, // Similar to .scrollableAxes, but for backward compatibility will also adjust the top & bottom contentInset when the scroll view is owned by a view controller with automaticallyAdjustsScrollViewInsets = YES inside a navigation controller, regardless of whether the scroll view is scrollable
UIScrollViewContentInsetAdjustmentScrollableAxes, // Edges for scrollable axes are adjusted (i.e., contentSize.width/height > frame.size.width/height or alwaysBounceHorizontal/Vertical = YES)
UIScrollViewContentInsetAdjustmentNever, // contentInset is not adjusted
UIScrollViewContentInsetAdjustmentAlways, // contentInset is always adjusted by the scroll view's safeAreaInsets
} API_AVAILABLE(ios(11.0),tvos(11.0));
UIScrollViewContentInsetAdjustmentBehavior是一个枚举类型,值有以下几种:
- automatic 和scrollableAxes一样,scrollView会自动计算和适应顶部和底部的内边距并且在scrollView 不可滚动时,也会设置内边距.
- scrollableAxes 自动计算内边距.
- never不计算内边距
- always 根据safeAreaInsets 计算内边距
适配:
if (@available(iOS 11.0, *)) {
NSLog(@"iOS11");
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0);
self.tableView.scrollIndicatorInsets = self.tableView.contentInset;
} else {
NSLog(@"非iOS11");
}