CustomTabbarController.m 12.4 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11

//
//  CustomTabbarController.m
//  Lighting
//
//  Created by 曹云霄 on 16/4/27.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CustomTabbarController.h"
#import "Toolview.h"
曹云霄's avatar
曹云霄 committed
12
#import "AppDelegate.h"
13 14 15
#import "SceneLibraryViewController.h"
#import "ProductLibraryViewController.h"
#import "AboutViewController.h"
曹云霄's avatar
曹云霄 committed
16 17
#import "AllCustomerViewController.h"
#import "CustomerOrderViewController.h"
曹云霄's avatar
曹云霄 committed
18
#import "UserViewController.h"
19
#import "ChangePasswordViewController.h"
勾芒's avatar
勾芒 committed
20
#import "SearchViewController.h"
勾芒's avatar
勾芒 committed
21
#import "BaseViewController.h"
勾芒's avatar
勾芒 committed
22
#import "QRViewController.h"
曹云霄's avatar
曹云霄 committed
23
#import "ExperienceCentreViewController.h"
曹云霄's avatar
曹云霄 committed
24
#import "RebateViewController.h"
曹云霄's avatar
曹云霄 committed
25 26 27
#import "GuideIntegralViewController.h"
#import "LearningCenterMainViewController.h"
#import "AnnouncementViewController.h"
28
#import "MessageViewController.h"
曹云霄's avatar
曹云霄 committed
29
#import "HomeViewController.h"
30
#import "CustomWKWebViewController.h"
曹云霄's avatar
曹云霄 committed
31

勾芒's avatar
勾芒 committed
32 33

@interface CustomTabbarController ()<TabbarButtonClickdelegate,ChangpasswordDelegate,CancelButtondelegate,UITextFieldDelegate>
曹云霄's avatar
曹云霄 committed
34 35

@property (nonatomic,strong) NSArray *identifierArray;
曹云霄's avatar
曹云霄 committed
36

37 38 39 40 41
/**
 *  保存按钮引用
 */
@property (nonatomic,strong) UIButton *Newbutton;

勾芒's avatar
勾芒 committed
42 43 44
/**
 *  控制器数组
 */
45
@property (nonatomic,strong) NSMutableArray *vcArray;
勾芒's avatar
勾芒 committed
46

曹云霄's avatar
曹云霄 committed
47 48 49 50 51
/**
 *  工具栏
 */
@property (nonatomic,strong) Toolview *toolview;

曹云霄's avatar
曹云霄 committed
52 53 54 55
@end

@implementation CustomTabbarController

曹云霄's avatar
曹云霄 committed
56 57 58 59 60 61 62 63 64
/**
 *  UIStoryboard Identifier数组
 *
 *  @return NSArary
 */
- (NSArray *)identifierArray
{
    if (_identifierArray == nil) {
        
65
        _identifierArray = [NSArray arrayWithObjects:@"HomeViewController",@"SearchViewController",@"ShoppingViewController",@"ClientViewController",@"RebateViewController",@"GuideIntegralViewController",@"AnnouncementViewController",@"MessageViewController",@"SceneLibraryViewController",@"ProductLibraryViewController",@"AllCustomerViewController",@"CustomerOrderViewController",@"LearningCenterMainViewController",@"AboutViewController", nil];
曹云霄's avatar
曹云霄 committed
66
    }
勾芒's avatar
勾芒 committed
67
    return _identifierArray;
曹云霄's avatar
曹云霄 committed
68 69
}

70 71 72 73 74 75 76 77
- (NSMutableArray *)vcArray
{
    if (!_vcArray) {
        _vcArray = [NSMutableArray array];
    }
    return _vcArray;
}

曹云霄's avatar
曹云霄 committed
78

勾芒's avatar
勾芒 committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.selectedViewController beginAppearanceTransition: YES animated: animated];
}

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.selectedViewController endAppearanceTransition];
}

-(void) viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.selectedViewController beginAppearanceTransition: NO animated: animated];
}

-(void) viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.selectedViewController endAppearanceTransition];
}

曹云霄's avatar
曹云霄 committed
103 104
- (void)viewDidLoad {
    [super viewDidLoad];
105
    
曹云霄's avatar
曹云霄 committed
106 107
    [self uiConfigAction];
    [self addViewcontroller];
108
    [self addNSNotification];
曹云霄's avatar
曹云霄 committed
109 110 111 112 113
}

#pragma mark -UI
- (void)uiConfigAction
{
114 115
    self.tabBar.frame = CGRectMake(ZERO, ZERO, ScreenWidth, NavigationHeight);
    self.toolview = [[Toolview alloc]initWithFrame:CGRectMake(ZERO, ZERO, ScreenWidth, NavigationHeight)];
曹云霄's avatar
曹云霄 committed
116 117
    self.toolview.delegate = self;
    self.toolview.inputField.delegate = self;
勾芒's avatar
勾芒 committed
118
    self.delegate = self;
119 120
    [self.view addSubview:self.toolview];
    self.tabBar.hidden = YES;
121 122 123 124 125
}

#pragma mark -监听通知
- (void)addNSNotification
{
勾芒's avatar
勾芒 committed
126
    //显示体验中心
127
    [Notification addObserver:self selector:@selector(showFollowHeart:) name:OPENFOLLOWHEARTVC object:nil];
128 129
    //显示体验中心3D
    [Notification addObserver:self selector:@selector(show3DFollowHeart:) name:OPENFOLLOWHEART3DVC object:nil];
130 131 132 133 134 135 136 137 138
    //显示消息界面
    [Notification addObserver:self selector:@selector(showMessageController:) name:NSNOTIFICATION_MESSAGE object:nil];
    //app未启动点击通知回调
    NSDictionary *dict = [UserDefault objectForKey:NSNOTIFICATION_MESSAGE];
    if (dict) {
        self.selectedIndex = 6;
        [Notification postNotificationName:NSNOTIFICATION_MESSAGE object:dict];
        [UserDefault removeObjectForKey:NSNOTIFICATION_MESSAGE];
    }
曹云霄's avatar
曹云霄 committed
139 140
}

141 142 143 144 145
#pragma mark -显示消息界面
- (void)showMessageController:(NSNotification *)object
{
    self.selectedIndex = 6;
}
曹云霄's avatar
曹云霄 committed
146

147
#pragma mark -添加controller到viewControllers
曹云霄's avatar
曹云霄 committed
148 149
- (void)addViewcontroller
{
150
    NSMutableArray *controllerArray = [NSMutableArray array];
曹云霄's avatar
曹云霄 committed
151
    UIStoryboard *storyboard = nil;
152
    for (int i=0; i<self.identifierArray.count; i++) {
曹云霄's avatar
曹云霄 committed
153 154 155
        
        NSString *controllString = self.identifierArray[i];
        // 公告
156
        if ([controllString isEqualToString:@"AnnouncementViewController"] || [controllString isEqualToString:@"MessageViewController"]) {
曹云霄's avatar
曹云霄 committed
157 158 159 160 161 162 163 164 165 166
            storyboard = [BaseViewController getAnnouncementStoryboardClass];
        }else if ([controllString isEqualToString:@"LearningCenterMainViewController"]) {
            // 学习中心
            storyboard = [BaseViewController getLearningCenterStoryboardClass];
        }else if ([controllString isEqualToString:@"GuideIntegralViewController"]) {
            // 积分
            storyboard = [BaseViewController getGuideIntegralStoryboardClass];
        }else {
            storyboard = [BaseViewController getMainStoryboardClass];
        }
167 168 169 170 171
        BaseViewController *control = [storyboard instantiateViewControllerWithIdentifier:self.identifierArray[i]];
        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:control];
        [self.vcArray addObject:nav];
        [controllerArray addObject:control];
    }
勾芒's avatar
勾芒 committed
172
    self.viewControllers = self.vcArray;
173
    SHARED_APPDELEGATE.allControllerArray = controllerArray;
曹云霄's avatar
曹云霄 committed
174
    SHARED_APPDELEGATE.tabBarController = self;
曹云霄's avatar
曹云霄 committed
175
    self.selectedIndex = 0;
176 177 178 179 180 181 182 183 184 185 186
}


#pragma mark -移除系统自带的UITabBarButton
- (void)viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    for (UIView *view in self.tabBar.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [view removeFromSuperview];
        }
    }
曹云霄's avatar
曹云霄 committed
187
}
曹云霄's avatar
曹云霄 committed
188

曹云霄's avatar
曹云霄 committed
189 190

#pragma amrk -TabbarButtonClickdelegate代理
191
- (void)buttonClickAction:(NSInteger)Buttontag withButton:(UIButton *)button
曹云霄's avatar
曹云霄 committed
192
{
曹云霄's avatar
曹云霄 committed
193 194
    [self.toolview.inputField resignFirstResponder];
    [self dismissViewControllerAnimated:NO completion:nil];
195
    _Newbutton = button;
曹云霄's avatar
曹云霄 committed
196 197
    switch (Buttontag) {
            
198
        case MENU:
曹云霄's avatar
曹云霄 committed
199 200 201 202
            
            [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
            
            break;
203 204
        case MESSAGE:
        {
205
            self.selectedIndex = 7;
206 207 208
        }
            break;
        case NOTICE:
曹云霄's avatar
曹云霄 committed
209
        {
210
            self.selectedIndex = 6;
曹云霄's avatar
曹云霄 committed
211 212
        }
            break;
213
        case SHOPPING_GUIDE:
曹云霄's avatar
曹云霄 committed
214
            
曹云霄's avatar
曹云霄 committed
215 216
        {
            UserViewController *userVC = [[UserViewController alloc]init];
217
            userVC.delegate = self;
218
            userVC.preferredContentSize = CGSizeMake(260, 230);
曹云霄's avatar
曹云霄 committed
219 220 221 222
            userVC.modalPresentationStyle = UIModalPresentationPopover;
            UIPopoverPresentationController *pop = userVC.popoverPresentationController;
            pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
            pop.sourceView = userVC.view;
223
            pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
曹云霄's avatar
曹云霄 committed
224 225
            [self presentViewController:userVC animated:YES completion:nil];
        }
曹云霄's avatar
曹云霄 committed
226
            break;
227
        case CUSTOMER:
曹云霄's avatar
曹云霄 committed
228
            
曹云霄's avatar
曹云霄 committed
229
            self.selectedIndex = 3;
曹云霄's avatar
曹云霄 committed
230 231
            
            break;
232
        case SHOPPING_CAR:
勾芒's avatar
勾芒 committed
233 234 235
            //必须设置当前客户才能跳转到购物车
            if (![Shoppersmanager manager].currentCustomer) {
                
236
                [XBLoadingView showHUDViewWithText:@"必须设置当前客户才能访问购物车"];
237
            }else{
勾芒's avatar
勾芒 committed
238
                
曹云霄's avatar
曹云霄 committed
239
                self.selectedIndex = 2;
勾芒's avatar
勾芒 committed
240
            }
曹云霄's avatar
曹云霄 committed
241 242
            
            break;
243
        
曹云霄's avatar
曹云霄 committed
244 245
        default:
            break;
曹云霄's avatar
曹云霄 committed
246
    }
曹云霄's avatar
曹云霄 committed
247 248
}

249 250 251 252 253 254 255 256 257 258 259 260
#pragma mark -修改密码点击
- (void)changPasswordButtonClick
{
    [self dismissViewControllerAnimated:NO completion:^{
        ChangePasswordViewController *changpassword = [[ChangePasswordViewController alloc]init];
        changpassword.delegate = self;
        changpassword.preferredContentSize = CGSizeMake(260, 180);
        changpassword.modalPresentationStyle = UIModalPresentationPopover;
        UIPopoverPresentationController *pop = changpassword.popoverPresentationController;
        pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
        pop.sourceView = changpassword.view;
        pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_Newbutton];
261
        [self presentViewController:changpassword animated:YES completion:nil];
262
    }];
曹云霄's avatar
曹云霄 committed
263
}
264 265 266 267 268 269 270 271


#pragma mark -取消按钮
- (void)cancelButtonClick
{
    [self dismissViewControllerAnimated:NO completion:^{
        UserViewController *userVC = [[UserViewController alloc]init];
        userVC.delegate = self;
272
        userVC.preferredContentSize = CGSizeMake(260, 230);
273 274 275 276 277 278 279 280 281
        userVC.modalPresentationStyle = UIModalPresentationPopover;
        UIPopoverPresentationController *pop = userVC.popoverPresentationController;
        pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
        pop.sourceView = userVC.view;
        pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:_Newbutton];
        [self presentViewController:userVC animated:YES completion:nil];
    }];
}

曹云霄's avatar
曹云霄 committed
282
#pragma mark -二维码扫描
283
- (void)qrcodeButtonClick
曹云霄's avatar
曹云霄 committed
284
{
曹云霄's avatar
曹云霄 committed
285
    WS(weakSelf);
286 287
    // 判断应用是否有使用相机的权限
    if(![BaseViewController determineCameraPermissions]){
288
        ShowAlertView(self, @"提示", @"请在iPad的“设置-隐私-相机”选项中,允许欧立方访问你的相机", nil, @"知道了", UIAlertControllerStyleAlert, nil, nil);
曹云霄's avatar
曹云霄 committed
289 290
    }else {
        QRViewController *qrVC = [[QRViewController alloc] initWithScanCompleteHandler:^(NSString *url) {
曹云霄's avatar
曹云霄 committed
291
            [weakSelf dismissViewControllerAnimated:YES completion:^{
292
                ProductLibraryViewController *product = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:8];
曹云霄's avatar
曹云霄 committed
293
                product.barcode = url;
294 295
                SHARED_APPDELEGATE.lineView.hidden = YES;
                weakSelf.selectedIndex = 8;
曹云霄's avatar
曹云霄 committed
296
            }];
297
        }];
曹云霄's avatar
曹云霄 committed
298 299 300 301
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf presentViewController:qrVC animated:YES completion:nil];
        });
    }
勾芒's avatar
勾芒 committed
302 303
}

勾芒's avatar
勾芒 committed
304

勾芒's avatar
勾芒 committed
305 306 307
#pragma mark -搜索框代理方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
曹云霄's avatar
曹云霄 committed
308
    self.selectedIndex = 1;
勾芒's avatar
勾芒 committed
309 310 311 312 313 314
    return YES;
}

#pragma mark -Search按钮
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
315
    if (![BaseViewController isBlankString:textField.text]) {
勾芒's avatar
勾芒 committed
316
        [textField resignFirstResponder];
317
        [Notification postNotificationName:SEARCHSTRING object:textField.text];
勾芒's avatar
勾芒 committed
318 319
    }
    return YES;
曹云霄's avatar
曹云霄 committed
320 321
}

勾芒's avatar
勾芒 committed
322 323 324 325
#pragma mark -自定义选中
- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    [super setSelectedIndex:selectedIndex];
326
    [self didSelectNavigationController:[SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:selectedIndex]];
勾芒's avatar
勾芒 committed
327 328
}

329 330
#pragma mark -返回根视图控制器
- (void)didSelectNavigationController:(UIViewController *)viewController
勾芒's avatar
勾芒 committed
331
{
332 333 334 335
    if ([[viewController.navigationController.viewControllers firstObject] isKindOfClass:NSClassFromString(@"UIMoreListController")]){
        [viewController.navigationController popToViewController:viewController.navigationController.viewControllers[1] animated:YES];
    }else{
        [viewController.navigationController popToRootViewControllerAnimated:YES];
勾芒's avatar
勾芒 committed
336 337 338
    }
}

曹云霄's avatar
曹云霄 committed
339 340 341
#pragma mark -  切换tabbar selectedIndex
- (void)switchSelectedIndex:(NSInteger)selectedIndex
{
342
    [self.toolview switchLineViewOrigin:selectedIndex-100];
曹云霄's avatar
曹云霄 committed
343 344
}

勾芒's avatar
勾芒 committed
345
#pragma mark -推出体验中心控制器
曹云霄's avatar
曹云霄 committed
346
- (void)showFollowHeart:(NSNotification *)objc
勾芒's avatar
勾芒 committed
347
{
348 349 350 351 352 353
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"OppleMain" bundle:nil];
    ExperienceCentreViewController *ExperienceCenter = [storyboard instantiateViewControllerWithIdentifier:@"ExperienceCentre"];
    ExperienceCenter.modalPresentationStyle = UIModalPresentationOverFullScreen;
    UIPopoverPresentationController *popover = ExperienceCenter.popoverPresentationController;
    popover.sourceView = ExperienceCenter.view;
    [self presentViewController:ExperienceCenter animated:YES completion:nil];
勾芒's avatar
勾芒 committed
354 355
}

356 357 358 359 360 361 362 363 364
#pragma mark -推出3D体验中心控制器
- (void)show3DFollowHeart:(NSNotification *)objc
{
    CustomWKWebViewController *webView = [[CustomWKWebViewController alloc] init];
    webView.type = Announcement;
    webView.urlString = @"http://ysj.zbj.com/oem/100001.html";
    [self presentViewController:webView animated:YES completion:nil];
    
}
勾芒's avatar
勾芒 committed
365

曹云霄's avatar
曹云霄 committed
366
@end