• OC使用inline替代宏


    
    CG_INLINE void
    GCDDelay(int64_t delayInSeconds,dispatch_block_t block){
        dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
        dispatch_after(popTime, dispatch_get_main_queue(),block);
    }
    
    CG_INLINE void
    GCDOnce( dispatch_once_t  onceToken,DISPATCH_NOESCAPE dispatch_block_t block){
        dispatch_once ( &onceToken, block);
    }
    
    CG_INLINE CGFloat
    WIDTH(){
        static CGFloat ScreenWidth;
        static dispatch_once_t  onceToken;
        GCDOnce(onceToken,^{
            ScreenWidth = CGRectGetWidth([UIScreen mainScreen].bounds);
        });
        return ScreenWidth;
    };
    
    
    CG_INLINE CGFloat
    HEIGHT(){
        static CGFloat ScreenHeight;
        static dispatch_once_t  onceToken;
        
        GCDOnce(onceToken,^{
            ScreenHeight = CGRectGetHeight([UIScreen mainScreen].bounds);
        });
        return ScreenHeight;
    };
    
    
    CG_INLINE CGRect
    SCREEN(){
        static CGRect ScreenRect;
        static dispatch_once_t  onceToken;
        
        GCDOnce(onceToken,^{
            if (CGRectIsEmpty(ScreenRect) || CGRectIsNull(ScreenRect)) {
                ScreenRect = [UIScreen mainScreen].bounds;
            }
        });
        return ScreenRect;
    };
    
    
    CG_INLINE CGFloat
    FontScale(){
        static CGFloat FScale;
        static dispatch_once_t  onceToken;
        
        GCDOnce(onceToken,^{
            FScale = 72.0/96.0;
        });
        return FScale;
    };
    
    
    CG_INLINE CGFloat
    SizeScaleX(){
        static CGFloat autoSizeScaleX;
        static dispatch_once_t  onceToken;
        
        GCDOnce(onceToken,^{
            autoSizeScaleX = (WIDTH()>480?WIDTH()/320.0:1.0);
        });
        return autoSizeScaleX;
    };
    
    
    CG_INLINE CGFloat
    SizeScaleY(){
        static CGFloat autoSizeScaleY;
        static dispatch_once_t  onceToken;
        
        GCDOnce(onceToken,^{
            autoSizeScaleY = (WIDTH()>480?HEIGHT()/568.0:1.0);
        });
        return autoSizeScaleY;
    };
    
    CG_INLINE CGRect
    CGLFLMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
    {
        CGRect rect;
        rect.origin.x = x *SizeScaleX();
        rect.origin.y = y *SizeScaleY();
        rect.size.width = width *SizeScaleX();
        rect.size.height = height *SizeScaleY();
        return rect;
    };
    
    CG_INLINE CGPoint
    CGPointLFLMake(CGFloat x, CGFloat y)
    {
        CGPoint pointLFL;
        pointLFL.x = x * SizeScaleX();
        pointLFL.y = y * SizeScaleY();
        return pointLFL;
    };
    
    CG_INLINE CGSize
    CGSizeLFLMake(CGFloat width, CGFloat height)
    {
        CGSize sizeLFL;
        sizeLFL.width = width* SizeScaleX();
        sizeLFL.height = height* SizeScaleY();
        return sizeLFL;
    };
    
  • 相关阅读:
    枚举--分巧克力--蓝桥杯--二分法
    枚举笔记之哈希表 四个平方和
    枚举 蓝桥杯 四个平方数和2--暴力解法 超时
    枚举例题之平方十位数思路无代码
    LeetCode----盛最多水的容器「贪心」
    2020校招笔试
    2020校招美团点评笔试
    2020校招搜狗笔试
    2020网易校招笔试
    2020校招途家名宿开发笔试
  • 原文地址:https://www.cnblogs.com/levy/p/OC-shi-yong-chang-liangbian-liang-ti-dai-hong.html
Copyright © 2020-2023  润新知