CustomTabbarController.m 12 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 16 17
#import "FollowHeartViewController.h"
#import "SceneLibraryViewController.h"
#import "ProductLibraryViewController.h"
#import "CustomerManagementViewController.h"
#import "AboutViewController.h"
曹云霄's avatar
曹云霄 committed
18 19
#import "AllCustomerViewController.h"
#import "CustomerOrderViewController.h"
曹云霄's avatar
曹云霄 committed
20
#import "UserViewController.h"
21
#import "ChangePasswordViewController.h"
勾芒's avatar
勾芒 committed
22
#import "SearchViewController.h"
勾芒's avatar
勾芒 committed
23
#import "BaseViewController.h"
勾芒's avatar
勾芒 committed
24
#import "QRViewController.h"
勾芒's avatar
勾芒 committed
25 26

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

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

30 31 32 33 34
/**
 *  保存按钮引用
 */
@property (nonatomic,strong) UIButton *Newbutton;

勾芒's avatar
勾芒 committed
35 36 37 38 39
/**
 *  控制器数组
 */
@property (nonatomic,strong) NSArray *vcArray;

曹云霄's avatar
曹云霄 committed
40 41 42 43
@end

@implementation CustomTabbarController

曹云霄's avatar
曹云霄 committed
44 45 46 47 48 49 50 51 52
/**
 *  UIStoryboard Identifier数组
 *
 *  @return NSArary
 */
- (NSArray *)identifierArray
{
    if (_identifierArray == nil) {
        
勾芒's avatar
勾芒 committed
53
        _identifierArray = [NSArray arrayWithObjects:@"searchvc",@"shopping",@"Client",@"followheart",@"scenelibrary",@"productlibrary",@"customermanager",@"allcustomer",@"customerorder",@"about", nil];
曹云霄's avatar
曹云霄 committed
54
    }
勾芒's avatar
勾芒 committed
55
    return _identifierArray;
曹云霄's avatar
曹云霄 committed
56 57 58
}


勾芒's avatar
勾芒 committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
-(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
83

曹云霄's avatar
曹云霄 committed
84 85 86 87
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
曹云霄's avatar
曹云霄 committed
88 89 90 91 92 93 94 95

    [self uiConfigAction];
    [self addViewcontroller];
}

#pragma mark -UI
- (void)uiConfigAction
{
曹云霄's avatar
曹云霄 committed
96 97
    self.tabBar.frame = CGRectMake(Zero, Zero, ScreenWidth, NavigationHeight);
    Toolview *toolview = [[Toolview alloc]initWithFrame:CGRectMake(Zero, Zero, ScreenWidth, NavigationHeight)];
曹云霄's avatar
曹云霄 committed
98
    toolview.delegate = self;
勾芒's avatar
勾芒 committed
99
    toolview.inputField.delegate = self;
勾芒's avatar
勾芒 committed
100
    self.delegate = self;
曹云霄's avatar
曹云霄 committed
101
    [self.tabBar addSubview:toolview];
曹云霄's avatar
曹云霄 committed
102 103 104
}


105
#pragma mark -添加controller到viewControllers
曹云霄's avatar
曹云霄 committed
106 107
- (void)addViewcontroller
{
108
    
曹云霄's avatar
曹云霄 committed
109
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"StoryboardwithCYX" bundle:nil];
勾芒's avatar
勾芒 committed
110 111 112 113 114 115 116 117 118 119
    SearchViewController *searchVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:0]];
    ShoppingViewController *shoppingVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:1]];
    ClientViewController *clientVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:2]];
    FollowHeartViewController *followVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:3]];
    SceneLibraryViewController *sceneVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:4]];
    ProductLibraryViewController *productVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:5]];
    CustomerManagementViewController *customerVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:6]];
    AllCustomerViewController *allcustomerVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:7]];
    CustomerOrderViewController *customerOrderVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:8]];
    AboutViewController *aboutVC = [storyboard instantiateViewControllerWithIdentifier:[self.identifierArray objectAtIndex_opple:9]];
120 121
    
    
勾芒's avatar
勾芒 committed
122
    UINavigationController *searchNav = [[UINavigationController alloc]initWithRootViewController:searchVC];
曹云霄's avatar
曹云霄 committed
123 124
    UINavigationController *shoppingNav = [[UINavigationController alloc]initWithRootViewController:shoppingVC];
    UINavigationController *clientNav = [[UINavigationController alloc]initWithRootViewController:clientVC];
125 126 127 128
    UINavigationController *followNav = [[UINavigationController alloc]initWithRootViewController:followVC];
    UINavigationController *sceneNav = [[UINavigationController alloc]initWithRootViewController:sceneVC];
    UINavigationController *productNav = [[UINavigationController alloc]initWithRootViewController:productVC];
    UINavigationController *customerNav = [[UINavigationController alloc]initWithRootViewController:customerVC];
曹云霄's avatar
曹云霄 committed
129 130
    UINavigationController *allcustomerNav = [[UINavigationController alloc]initWithRootViewController:allcustomerVC];
    UINavigationController *cutomerorderNav = [[UINavigationController alloc]initWithRootViewController:customerOrderVC];
131 132
    UINavigationController *aboutNav = [[UINavigationController alloc]initWithRootViewController:aboutVC];
    
勾芒's avatar
勾芒 committed
133 134
    self.vcArray = [NSArray arrayWithObjects:aboutNav,cutomerorderNav,allcustomerNav,customerNav,productNav,sceneNav,followNav,clientNav,shoppingNav,searchNav, nil];
    self.viewControllers = self.vcArray;
勾芒's avatar
勾芒 committed
135
    SHARED_APPDELEGATE.allControllerArray = [NSArray arrayWithObjects:aboutVC,customerOrderVC,allcustomerVC,customerVC,productVC,sceneVC,followVC,clientVC,shoppingVC,searchVC, nil];
曹云霄's avatar
曹云霄 committed
136
    self.selectedIndex = 7;
137 138 139 140 141 142 143 144 145 146 147 148 149
}


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

曹云霄's avatar
曹云霄 committed
152 153

#pragma amrk -TabbarButtonClickdelegate代理
曹云霄's avatar
曹云霄 committed
154
- (void)ButtonClickAction:(NSInteger)Buttontag withButton:(UIButton *)button
曹云霄's avatar
曹云霄 committed
155
{
156
    _Newbutton = button;
曹云霄's avatar
曹云霄 committed
157 158
    switch (Buttontag) {
            
曹云霄's avatar
曹云霄 committed
159
            //右侧视图
曹云霄's avatar
曹云霄 committed
160 161
        case 100:
            
勾芒's avatar
勾芒 committed
162
            [self dismissViewControllerAnimated:YES completion:nil];
曹云霄's avatar
曹云霄 committed
163 164 165
            [SHARED_APPDELEGATE.mmdrawer toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
            
            break;
曹云霄's avatar
曹云霄 committed
166 167
            
            //某某用户
曹云霄's avatar
曹云霄 committed
168 169
        case 101:
            
曹云霄's avatar
曹云霄 committed
170 171
        {
            UserViewController *userVC = [[UserViewController alloc]init];
172
            userVC.delegate = self;
曹云霄's avatar
曹云霄 committed
173 174 175 176 177
            userVC.preferredContentSize = CGSizeMake(260, 170);
            userVC.modalPresentationStyle = UIModalPresentationPopover;
            UIPopoverPresentationController *pop = userVC.popoverPresentationController;
            pop.permittedArrowDirections = UIPopoverArrowDirectionAny;
            pop.sourceView = userVC.view;
178
            pop.barButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
曹云霄's avatar
曹云霄 committed
179 180
            [self presentViewController:userVC animated:YES completion:nil];
        }
曹云霄's avatar
曹云霄 committed
181
            break;
曹云霄's avatar
曹云霄 committed
182 183
            
            //我的客户
曹云霄's avatar
曹云霄 committed
184 185
        case 102:
            
勾芒's avatar
勾芒 committed
186
            [self dismissViewControllerAnimated:YES completion:nil];
曹云霄's avatar
曹云霄 committed
187
            self.selectedIndex = 7;
曹云霄's avatar
曹云霄 committed
188 189
            
            break;
曹云霄's avatar
曹云霄 committed
190 191
            
            //购物车
曹云霄's avatar
曹云霄 committed
192 193
        case 103:
            
勾芒's avatar
勾芒 committed
194
            [self dismissViewControllerAnimated:YES completion:nil];
勾芒's avatar
勾芒 committed
195 196 197 198
            //必须设置当前客户才能跳转到购物车
            if (![Shoppersmanager manager].currentCustomer) {
                
                MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];
勾芒's avatar
勾芒 committed
199 200 201 202 203 204 205 206
                hud.labelText = @"必须设置当前客户才能访问购物车";
                hud.margin = 10.f;
                hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
                hud.minSize = CGSizeMake(200, 50);
                hud.animationType = MBProgressHUDAnimationZoom;
                hud.mode = MBProgressHUDModeText;
                hud.removeFromSuperViewOnHide = YES;
                [hud hide:YES afterDelay:1.0f];
勾芒's avatar
勾芒 committed
207 208
            }else
            {
勾芒's avatar
勾芒 committed
209
                
勾芒's avatar
勾芒 committed
210 211
               self.selectedIndex = 8;
            }
曹云霄's avatar
曹云霄 committed
212 213 214 215 216
            
            break;
            
        default:
            break;
曹云霄's avatar
曹云霄 committed
217
    }
曹云霄's avatar
曹云霄 committed
218 219
}

220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#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];
        [self presentViewController:changpassword animated:YES completion:nil];
        
    }];
曹云霄's avatar
曹云霄 committed
236
}
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257



#pragma mark -取消按钮
- (void)cancelButtonClick
{
    [self dismissViewControllerAnimated:NO completion:^{
        
        UserViewController *userVC = [[UserViewController alloc]init];
        userVC.delegate = self;
        userVC.preferredContentSize = CGSizeMake(260, 170);
        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
258

曹云霄's avatar
曹云霄 committed
259 260 261
#pragma mark -二维码扫描
- (void)QrcodeButtonClick
{
勾芒's avatar
勾芒 committed
262
    
勾芒's avatar
勾芒 committed
263
    QRViewController *qrVC = [[QRViewController alloc] initWithScanCompleteHandler:^(NSString *url) {
264 265 266 267 268 269
        [self dismissViewControllerAnimated:YES completion:^{
            
            ProductLibraryViewController *product = [SHARED_APPDELEGATE.allControllerArray objectAtIndex_opple:4];
            product.barcode = url;
            self.selectedIndex = 4;
        }];
勾芒's avatar
勾芒 committed
270
    }];
勾芒's avatar
勾芒 committed
271
    [self presentViewController:qrVC animated:YES completion:nil];
勾芒's avatar
勾芒 committed
272 273
}

勾芒's avatar
勾芒 committed
274

勾芒's avatar
勾芒 committed
275 276 277
#pragma mark -搜索框代理方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
勾芒's avatar
勾芒 committed
278
        //返回根视图
勾芒's avatar
勾芒 committed
279 280
    [[NSNotificationCenter defaultCenter] postNotificationName:POPROOTCONTROLLER object:nil];
    self.selectedIndex = 9;
勾芒's avatar
勾芒 committed
281
   
勾芒's avatar
勾芒 committed
282 283 284 285 286 287 288 289 290
    return YES;
}


#pragma mark -Search按钮
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    
    //搜索
勾芒's avatar
勾芒 committed
291
    if (textField.text.length != 0) {
勾芒's avatar
勾芒 committed
292 293
        
        [textField resignFirstResponder];
勾芒's avatar
勾芒 committed
294 295
        //搜索
        [[NSNotificationCenter defaultCenter] postNotificationName:SEARCHSTRING object:textField.text];
勾芒's avatar
勾芒 committed
296 297
    }
    return YES;
曹云霄's avatar
曹云霄 committed
298 299
}

勾芒's avatar
勾芒 committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
#pragma mark -自定义选中
- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    [super setSelectedIndex:selectedIndex];
    [self tabBarController:self didSelectViewController:[self.vcArray objectAtIndex_opple:selectedIndex]];
}


#pragma mark -回到最上层
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if ([viewController isKindOfClass:[UINavigationController class]]) {
        
        UINavigationController *navVC = (UINavigationController *)viewController;
        [navVC popToRootViewControllerAnimated:NO];
    }
    
}

曹云霄's avatar
曹云霄 committed
319

勾芒's avatar
勾芒 committed
320

曹云霄's avatar
曹云霄 committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end