xn_base_BaseViewController.m 6.28 KB
//
//  xn_base_BaseViewController.m
//  xn_base_ios
//
//  Created by 钱鋆 on 15/12/16.
//  Copyright © 2015年 xn. All rights reserved.
//

#import "xn_base_BaseViewController.h"
#import <AudioToolbox/AudioToolbox.h>

@interface xn_base_BaseViewController (){
    CGFloat _viewHeight;
    BOOL isHotspot;
}

@end

@implementation xn_base_BaseViewController

@synthesize organizationId;
@synthesize mainLayout;
#pragma mark 创建单例
/**
 *  @author qianjun
 *
 *  @brief  创建单例
 *
 *  @return self
 */
+ (instancetype)sharedInstance {
    static id sharedInstance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[self alloc] init];
    });
    return sharedInstance;
}

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    for (UIView *child in self.tabBarController.tabBar.subviews) {
        if ([child isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [child removeFromSuperview];
        }
    }
//    if([[CommFun sharedInstance] f_flagWithOpenHotSpot]){
//        if (!isHotspot) {
//            self.mainLayout.frame = CGRectMake(self.mainLayout.frame.origin.x, self.mainLayout.frame.origin.y+20, self.mainLayout.frame.size.width, self.mainLayout.frame.size.height+20);
//            isHotspot = YES;
//        } else {
//            isHotspot = NO;
//        }
//    }
}

#pragma mark dealloc
- (void)dealloc
{
    // 删除AF返回的通知
//    [[NSNotificationCenter defaultCenter] removeObserver:self name:kResponseNotiName object:nil];
}

#pragma mark 导航存在情况下的返回事件
/**
 *  @author qianjun
 *
 *  @brief 导航存在情况下的返回事件
 */
-(void)f_backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 移除HUD
/**
 *  @author qianjun
 *
 *  @brief  移除HUD
 */
-(void)f_HUD_remove
{
//    if (HUD) {
//        [self f_HUD_hide];
//        if (HUD) {
//            [HUD removeFromSuperview];
//        }
//        HUD = nil;
//    }
}

#pragma mark 创建HUD
/**
 *  @author qianjun
 *
 *  @brief  创建HUD
 */
-(void)f_HUD_create
{
//    [self f_HUD_remove];
    // 加载数据
//    HUD = [[MBProgressHUD alloc] initWithView:self.mainLayout];
//    [self.mainLayout addSubview:HUD];
//    HUD = [[MBProgressHUD alloc] initWithWindow:[[[UIApplication sharedApplication] delegate] window]];
//    [[[[UIApplication sharedApplication] delegate] window] addSubview:HUD];
//    HUD.mode = MBProgressHUDModeIndeterminate;
}

#pragma mark 显示HUD
/**
 *  @author qianjun
 *
 *  @brief  显示HUD
 */
-(void)f_HUD_show
{
    dispatch_async(dispatch_get_main_queue(), ^{
//        [self l_creatHUD];
//        [self->HUD show:YES];
//        [self->HUD.superview bringSubviewToFront:self->HUD];
    });
}

#pragma mark 隐藏HUD
/**
 *  @author qianjun
 *
 *  @brief 隐藏HUD
 */
-(void)f_HUD_hide
{
    dispatch_async(dispatch_get_main_queue(), ^{
//        [self->HUD hide:YES];
    });
}

#pragma mark UIViewController Delegate
- (void)viewDidLoad {
    [super viewDidLoad];
    
  
  
    self.modalPresentationStyle = UIModalPresentationFullScreen;
    
    // 隐藏导航栏底部黑线
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
//    [self.view setBackgroundColor:COLOR_C_background];
    mainLayout = [[UIView alloc]init];
//    [mainLayout setBackgroundColor:COLOR_C_background];
    [self.view addSubview:mainLayout];
    [mainLayout mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.edges.equalTo(self.view);
        } else {
            make.edges.equalTo(self.view);
        }
    }];
    // 部分页面直接读取了mainLayout的size来设定子控件,这里需要立即获取控件大小
    [self.view layoutIfNeeded];
    //[self f_HUD_create];
}

-(void)f_resetSafeArea
{
    [mainLayout mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.edges.equalTo(self.view);
        } else {
            make.edges.equalTo(self.view);
        }
    }];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    NSLog(@"%@, %@", self, self.view);

  
    for (UIView *child in self.tabBarController.tabBar.subviews) {
        if ([child isKindOfClass:[UIControl class]]) {
            [child removeFromSuperview];
        }
    }
//    self.edgesForExtendedLayout = UIRectEdgeNone;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
    //UIStatusBarStyleDefault = 0 黑色文字,浅色背景时使用
    //UIStatusBarStyleLightContent = 1 白色文字,深色背景时使用
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
  
}

-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (void)l_foregroundTask:(NSDictionary *)userInfo
{
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 网络请求的回调
/**
 *  @author qianjun
 *
 *  @brief 网络请求的回调
 *
 *  @param noti 通知对象
 */
-(void)l_responseNoti:(NSNotification *)noti
{
    if (_sel_clientResponse) {
        [self performSelectorInBackground:_sel_clientResponse withObject:noti];
    }
}

-(float)mStatusbarHeight{
    //状态栏高度
    return [[UIApplication sharedApplication] statusBarFrame].size.height;
}

-(float)mNavigationbarHeight{
    //导航栏高度+状态栏高度
    return self.navigationController.navigationBar.frame.size.height + [[UIApplication sharedApplication] statusBarFrame].size.height;
}

-(float)mTabbarHeight{
    //Tabbar高度
    return self.tabBarController.tabBar.bounds.size.height;
}

-(void)l_creatHUD{
//    if (HUD == nil) {
//        HUD = [[MBProgressHUD alloc]init];
//        [self.mainLayout addSubview:HUD];
//    }
//    HUD.mode = MBProgressHUDModeIndeterminate;
}

-(void)l_writeLifeCycleLog:(NSString *)lifeCycle
{
//    NSMutableDictionary *_dic = [[NSMutableDictionary alloc]init];
//    [_dic setObject:NSStringFromClass([self class]) forKey:@"file_name"];
//    [_dic setObject:lifeCycle forKey:@"method"];
//    [[LoganHandler sharedInstance] wEvent:@"app.page.lifecycle" data:[[CommFun sharedInstance] f_toJSONString:_dic]];
}

@end