KWMMainVC.m 7.64 KB
Newer Older
houweibin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//
//  KWMMainVC.m
//  iToYoung
//
//  Created by jason on 16/5/9.
//  Copyright © 2016年 kollway. All rights reserved.
//

#import "KWMMainVC.h"
#import "UIColor+SAMAdditions.h"
#import "AppDelegate.h"
#import "KWMUserDao.h"
#import "MBProgressHUD.h"
#import "PSPDFAlertView.h"
#import "KWMWebViewVC.h"
#import "KWMStringUtil.h"
#import "KWMSplashView.h"
#import "KWMUserModel.h"
#import "KWMLoginVC.h"
lee committed
20
#import "KWMShoppingCart.h"
houweibin committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

@interface KWMMainVC ()

@property (nonatomic) KWMSplashView *splashView;

@end

@implementation KWMMainVC{
    BOOL isInApp;
    NSInteger tabBarHeight;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestExchangeRateApi];
40
//    [self initSplash];
houweibin committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54
    [self loadTabBar];
    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
    BOOL registerSuccess = [defaults boolForKey:KEY_USER_REGISTER];

    if(registerSuccess){
        MBProgressHUD *toastHUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        toastHUD.userInteractionEnabled = NO;
        toastHUD.mode = MBProgressHUDModeText;
        toastHUD.labelText = @"欢迎来到Cemarose";
        toastHUD.removeFromSuperViewOnHide = YES;
        [toastHUD hide:YES afterDelay:2];
        [defaults setBool:NO forKey:KEY_USER_REGISTER];
        [defaults synchronize];
    }
lee committed
55 56
//    [[KWMAPIManager sharedManager] loginWebSuccess:nil failure:nil];
    [[KWMUserDao shareDao] login];
lee committed
57
    [[KWMUserDao shareDao] requestTags];
lee committed
58 59 60 61
    [[KWMShoppingCart sharedInstance] allItemsWithCallback:^(NSError *error, KWMCartResult *cart) {
        
    }];
    
houweibin committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
}

- (void)initSplash{

    
    [self hiddenTheTabBar];
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];

    for (UIView *v in [self.view subviews]) {
        if ([v isKindOfClass:[UITabBar class]]) {
            CGRect frame = v.frame;
            tabBarHeight = frame.size.height;
        }
    }
    
    CGRect rectStatus = [[UIApplication sharedApplication] statusBarFrame];
    NSInteger statusHeight = rectStatus.size.height;

    self.splashView=[[KWMSplashView alloc] initWithFrame:CGRectMake(0,statusHeight,
                                                                         UI_SCREEN_WIDTH, UI_SCREEN_HEITHT-tabBarHeight-statusHeight)];
    
    
    [self.view addSubview:self.splashView];
    [self performSelector:@selector(showTheTabBar) withObject:nil afterDelay:3.0f];
}



//隐藏标签栏
- (void)hiddenTheTabBar
{
    //隐藏是不需要动画的
//    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isHiddenTabBar"]) {
        for (UIView *v in [self.view subviews]) {
            if ([v isKindOfClass:[UITabBar class]]) {
                //[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
                    CGRect frame = v.frame;
                    frame.origin.y += 49.0f;
                    v.frame = frame;
                //} completion:nil];
            } else {
                //[UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
                    CGRect frame = v.frame;
                    frame.size.height += 49.0f;
                    v.frame = frame;
                //} completion:nil];
            }
        }
//        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isHiddenTabBar"];

//    }
}







//显示标签栏
- (void)showTheTabBar
{

//    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"isHiddenTabBar"]) {
        for (UIView *v in [self.view subviews]) {
            if ([v isKindOfClass:[UITabBar class]]) {
                [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
                    CGRect frame = v.frame;
                    frame.origin.y -= 49.0f;
                    v.frame = frame;
                } completion:^(BOOL finished){
                    [self.splashView hide];
                }];
            } else {
                [UIView animateWithDuration:0.5f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(){
                    CGRect frame = v.frame;
                    frame.size.height -= 49.0f;
                    v.frame = frame;
                } completion:nil];
            }
        }
//        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isHiddenTabBar"];
//    }
}



-(void)showTabBar{
    [self.tabBarController.tabBar setHidden:NO];
}

- (void)loadTabBar {
    
    
    //UITabBar样式
    UITabBar *tabBar = self.tabBar;
    
    [UITabBarItem.appearance setTitleTextAttributes:@{
                                                      NSForegroundColorAttributeName : [UIColor sam_colorWithHex:@"#F1929A"], NSFontAttributeName :[UIFont systemFontOfSize:11.0f]} forState:UIControlStateSelected];
    
    [UITabBarItem.appearance setTitleTextAttributes:@{
                                                      NSForegroundColorAttributeName : [UIColor sam_colorWithHex:@"#666666"],
                                                      NSFontAttributeName :[UIFont systemFontOfSize:11.0f]} forState:UIControlStateNormal];
    
    
    
    
    UITabBarItem *tabBarItem1 = (tabBar.items)[0];
    UITabBarItem *tabBarItem2 = (tabBar.items)[1];
    UITabBarItem *tabBarItem3 = (tabBar.items)[2];
    UITabBarItem *tabBarItem4 = (tabBar.items)[3];
    
    UIImage *image1 = [[UIImage imageNamed:@"ic_tab_home_nor"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem1.image = image1;
    image1 = [[UIImage imageNamed:@"bttn_tab_home_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem1.selectedImage = image1;
    
    
    UIImage *image2 = [[UIImage imageNamed:@"btn_tab_store"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem2.image = image2;
    image2 = [[UIImage imageNamed:@"btn_tab_store_pre"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem2.selectedImage = image2;
184
    tabBarItem2.tag = 101;
houweibin committed
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
    
    
    UIImage *image3 = [[UIImage imageNamed:@"btn_tab_ brand"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem3.image = image3;
    image3 = [[UIImage imageNamed:@"btn_tab_ brand_pre"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem3.selectedImage = image3;
    
    UIImage *image4 = [[UIImage imageNamed:@"btn_tab_mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem4.image = image4;
    image4 = [[UIImage imageNamed:@"ic_tab_mine_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    tabBarItem4.selectedImage = image4;
    //缩小文字与图标的距离
    for(UITabBarItem *item in tabBar.items){
        [item setTitlePositionAdjustment:UIOffsetMake(0, 0)];
    }
    
}


-(void)requestExchangeRateApi{
    
    void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
lee committed
207
        NSLog(@"%@",error);
houweibin committed
208 209 210
    };
    void(^success)(NSURLSessionDataTask *,KWMExchangeRateResult *) = ^(NSURLSessionDataTask *task,KWMExchangeRateResult *result){
        if(result){
lee committed
211 212
//            NSNumber *exchangeRate = result.exchangeRate;
            [[KWMUserDao shareDao] saveExchangeRate:result.exchange_rate];
houweibin committed
213 214 215 216 217 218 219
        }
    };
    [[KWMAPIManager sharedManager] getExchangeRate:nil success:success failure:failure];
    
    
}

220 221 222 223 224 225 226
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    // 这里不需要调用super,因为父类没有实现这个代理方法
    //[super tabBar:tabBar didSelectItem:item];
    if(item.tag == 101){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didSelectCategoryTab" object:nil];
    }
}
houweibin committed
227 228

@end