iOS某些实用方法注释

一、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");
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容