美文网首页
项目结构-2021-01-05

项目结构-2021-01-05

作者: 勇往直前888 | 来源:发表于2022-03-29 09:03 被阅读0次

    文件结构

    image.png
    • 典型的4个tab结构,对应的首页每个tab一个文件夹
    image.png
    • 登录注册时独立的模块
    image.png image.png
    • 纯代码写界面,所以故事版是空白的;

    • 图片资源集中在一起,目录结构跟tab也大致对应;

    简评

    • 纯代码写界面,这个与本人习惯不一致,需要好好学习一下;

    • 整个目录按照类别,按照tab的含义来命名文件夹,简单直观;

    • 把网络,工具,配置常数等独立成一个个文件夹,分类比较清晰;

    • 对于第1版来说,这个项目结构是合适的,简单直观;

    Configure配置参数

    这个目录主要是一些宏定义,定义一些常数,常用的宏等等

    • 一些常见的尺寸常数,用宏表示很方便
    /** 距离 **/
    #define SCREEN_BOUNDS               [UIScreen mainScreen].bounds
    #define SCREEN_SCALE                [[UIScreen mainScreen] scale]
    #define SCREEN_SIZE                 [UIScreen mainScreen].bounds.size
    #define SCREEN_WIDTH                [UIScreen mainScreen].bounds.size.width
    #define SCREEN_HEIGHT               [UIScreen mainScreen].bounds.size.height
    
    • 屏幕适配,按照iPhone6的尺寸做,然后等比例缩放:
    //根据iPhone6的屏幕大小缩放,适配当前屏幕
    #define AutoScaleWidth(x)           ((SCREEN_WIDTH/375.00) * (x))
    #define AutoScaleHeight(x)          ((SCREEN_HEIGHT/667.00) * (x))
    
    • 安全区域,用了个自定义方法:iOS11之后的新特性,以前的是全0
    //安全区域
    #define SAFEAREAINSETS [XLHelperTool xl_safeAreaInsets]
    
    + (UIEdgeInsets)xl_safeAreaInsets {
        UIWindow *window = [UIApplication sharedApplication].windows.firstObject;
        if (![window isKeyWindow]) {
            UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
            if (CGRectEqualToRect(keyWindow.bounds, [UIScreen mainScreen].bounds)) {
                window = keyWindow;
            }
        }
        if (@available(iOS 11.0, *)) {
            UIEdgeInsets insets = [window safeAreaInsets];
            return insets;
        }
        return UIEdgeInsetsZero;
    }
    
    • 状态栏高度,默认20,iOS11之后要加上安全边界UIEdgeInsetstop
    //状态栏高度
    #define STATUSBAR_HEIGHT (([UIWindow instancesRespondToSelector:@selector(safeAreaInsets)]) ? (SAFEAREAINSETS.top ?: 20) : 20)
    
    • 顶部(导航栏+状态栏),底部(Tab+安全区域下边界;不考虑工具栏)
    //距离底部安全距离
    #define SAFEAREA_BOTTOM_HEIGHT SAFEAREAINSETS.bottom
    //导航栏高度
    #define NAVIGATIONBAR_HEIGHT     (44 + STATUSBAR_HEIGHT)
    //tabar高度
    #define XL_TABBAR_HEIGHT         (49 + SAFEAREA_BOTTOM_HEIGHT)
    
    • 网络配置的一些常数在这里:
    //开发环境
    //#define XLServerHttpDomain @"http://10.166.8.14:8130/"
    
    //测试环境
    #define XLServerHttpDomain @"https://appuat.mirrorftech.com/"
    
    //公网测试
    //#define XLServerHttpDomain @"https://apptest.mirrorftech.com/"
    
    • 16进制数字转颜色,这是跟UI沟通的一种重要方式:
    //颜色
    #define COLOR_WITH_HEX(color)       [UIColor colorWithHex:(color) alpha:1.0]
    
    + (instancetype)colorWithHex:(NSInteger)hexValue {
        return [UIColor colorWithHex:hexValue alpha:1.0f];
    }
    
    + (instancetype)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alpha {
        return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0
                               green:((float)((hexValue & 0xFF00) >> 8)) / 255.0
                                blue:((float)(hexValue & 0xFF)) / 255.0
                               alpha:alpha];
    }
    
    • 著名的weakSelf,strongSelf
    //弱引用
    #define WEAKSELF                    typeof(self) __weak weakSelf=self;
    //强引用
    #define STRONGSELF                  __strong __typeof(weakSelf) strongSelf = weakSelf;
    
    • 版本号:
    // 用户看到的1.0.0之类的
    #define SYSTEM_VERSION              [[UIDevice currentDevice] systemVersion]
    
    //app版本; build号;一个数字比如123
    #define XLAPPVERSION         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
    
    • 程序入口,从AppDelegete移到了这里
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        
        //界面初始配置
        [self.startUpConfig configAppWithApplication:application launchOptions:launchOptions];
        
        return YES;
    }
    
    - (void)configAppWithApplication:(UIApplication *)application
                       launchOptions:(NSDictionary *)launchOptions {
        UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
        XLBaseTabBarController *tabbarVC = [[XLBaseTabBarController alloc] init];
        window.rootViewController = [[XLBaseNavigationController alloc] initWithRootViewController:tabbarVC];
        [AppDelegate sharedInstance].window = window;
        [AppDelegate sharedInstance].navigationController = (XLBaseNavigationController *)window.rootViewController;
        [window makeKeyAndVisible];
        window.backgroundColor = [UIColor whiteColor];
        [[DTFrameworkInterface sharedInstance] manualInitMpaasFrameworkWithApplication:application launchOptions:launchOptions];
        
        if (XLLogEnable) {
            [XLAppLog setLogEnable:YES];
        } else {
            [XLAppLog setLogEnable:NO];
        }
        
        NSString *token = [XLUserDefaults getLastAvailableToken];
        [XLNetworking updateCustomHeaderDicWithToken:token];
        
        // 判断网络权限
        [ZYNetworkAccessibity start];
        
        //配置消息推送
        [self.pushTool configXLPush];
        
        //设置IQ键盘
        [self keyBoardConfig];
        
        //设置UI整体样式
        [self.uiConfig configUI];
        
        //直接进入首页
        [self jumpMainControllerWithVC:nil];
    }
    

    DTFrameworkInterface这是mPaaS的初始化入口

    • 日志,以文件的形式保存在手机中,命名格式是:yyyy-MM-dd.log
    +(void)redirectNSLogToFile
    {
        if(NO==gEnableXLLog)
            return;
        //如果已经连接Xcode调试则不输出到文件
        if(isatty(STDOUT_FILENO)) {
            return;
        }
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *logDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Log"];
        
        NSFileManager *fileManager = [NSFileManager defaultManager];
        BOOL fileExists = [fileManager fileExistsAtPath:logDirectory];
        if (!fileExists) {
            [fileManager createDirectoryAtPath:logDirectory  withIntermediateDirectories:YES attributes:nil error:nil];
        }
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]];
        [formatter setDateFormat:@"yyyy-MM-dd"]; //每次启动后都保存一个新的日志文件中
        NSString *dateStr = [formatter stringFromDate:[NSDate date]];
        NSString *logFilePath = [logDirectory stringByAppendingFormat:@"/%@.log",dateStr];
        
        // 将log输入到文件
        freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stdout);
        freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding], "a+", stderr);
        
    }
    

    相关文章

      网友评论

          本文标题:项目结构-2021-01-05

          本文链接:https://www.haomeiwen.com/subject/xuzioktx.html