码迷,mamicode.com
首页 > 其他好文 > 详细

关于 LYCHolyContentController 的使用记录

时间:2015-03-08 15:48:58      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:ios   框架设计   objective-c   

通过多次实践后,会开始萌发一种设计框架的想法。

其实也没有什么高上档的,也就是为了可以更加懒惰,过的更加快乐而已。

思路很简单,控制加载过程,以及自动执行释放的事件。


补充:

方便、快速、优化、强大的设计是需要很多实践来测试、维护、修改来确定的。


下面上代码了。


//
//  MainController.h
//  某项目
//
//  Created by yococo on 3/7/15.
//  Copyright (c) 2015 yococo. All rights reserved.
//

#import "LYCHolyContentController.h"

@interface MainController : LYCHolyContentController

+ (MainController *)sharedInstance;

@end


//
//  MainController.m
//  某项目
//
//  Created by yococo on 3/7/15.
//  Copyright (c) 2015 yococo. All rights reserved.
//

#import "MainController.h"

#import "IndexController.h"
#import "BrandController.h"
#import "LocationController.h"
#import "ProjectController.h"
#import "SmartController.h"
#import "StrollController.h"
#import "FormatsController.h"
#import "PropertyController.h"

#import "MainModel.h"

@interface MainController ()<LYCHolyContentControllerDelgate>

//  需要加载的对象
@property (nonatomic, strong) IndexController *indexController;
@property (nonatomic, strong) BrandController *brandController;
@property (nonatomic, strong) LocationController *locationController;
@property (nonatomic, strong) ProjectController *projectController;
@property (nonatomic, strong) SmartController *smartController;
@property (nonatomic, strong) StrollController *strollController;
@property (nonatomic, strong) FormatsController *formatsController;
@property (nonatomic, strong) PropertyController *propertyController;

@end

@implementation MainController

+ (MainController *)sharedInstance
{
    static MainController *singleton;
    static dispatch_once_t token;
    dispatch_once(&token,^{
        singleton = [MainController LYCControllerWithViewDirectionHorizontal];
    });
    return singleton;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)loadView
{
    [super loadView];
    
    //  设置协议
    self.lycHolyContentControllerDelgate = self;
    
    //  设置控制视图的大小位置
    CGRect tempRect = self.lycHolyControlView.frame;
    tempRect.size.height = 75;
    tempRect.origin.y = self.lycCurrentBounds.size.height - 75;
    self.lycHolyControlViewRect = tempRect;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //  触发按钮事件。
    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
}

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

- (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.
}
*/

#pragma mark - 设置按钮
- (NSArray *)lycHolyContentController:(LYCHolyContentController *)contentController buttonOnControlView:(UIView *)view
{
    return [MainModel controlButtons];
}

#pragma mark - 设置控制视图背景图
- (void)lycHolyContentController:(LYCHolyContentController *)contentController controlBackgroundImageView:(UIImageView *)imageView
{
    imageView.image = [UIImage LYCImageWithDatasource:LYC__PathFromBundleAppendingPathComponent(@"导航背景.png")];
}

#pragma mark - 设置按钮触发事件
- (void)lycHolySystemEventLoadViewControllerWithButton:(LYCHolyButton *)button
{
    switch (button.lycHolyIdentificationStyle) {
        case LYCHolyIdentificationStyleIndex:
        {
            //  不隐藏控制视图
            self.lycHolyControlViewHidden = NO;
            
            //  设置按钮状态
            [self lycHolyShowButtonSelectedState];
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 IndexController对象
                self.indexController = [IndexController LYCControllerXIBWithViewDirectionHorizontal];
                [self.indexController lycUnloadViewControllerWithBlock:^{
                    //  卸载 IndexController对象后,加载 SmartController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleNews];
                }];
            } complete:^{
                //  加载 IndexController对象
                [self lycHolyAddViewController:self.indexController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleBrand:
        {
            //  不隐藏控制视图
            self.lycHolyControlViewHidden = NO;
            
            //  设置按钮状态
            [self lycHolyShowButtoNormalStateAndOthersSelectedStateWithCurrentIdentificationStyle];
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 BrandController对象
                self.brandController = [BrandController LYCControllerXIBWithViewDirectionHorizontal];
                [self.brandController lycUnloadViewControllerWithBlock:^{
                    //  卸载 BrandController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 BrandController对象
                [self lycHolyAddViewController:self.brandController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleLocation:
        {
            //  隐藏控制视图
            self.lycHolyControlViewHidden = YES;
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 LocationController对象
                self.locationController = [LocationController LYCControllerXIBWithViewDirectionHorizontal];
                [self.locationController lycUnloadViewControllerWithBlock:^{
                    //  卸载 LocationController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 LocationController对象
                [self lycHolyAddViewController:self.locationController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleProject:
        {
            //  隐藏控制视图
            self.lycHolyControlViewHidden = YES;
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 ProjectController对象
                self.projectController = [ProjectController LYCControllerXIBWithViewDirectionHorizontal];
                [self.projectController lycUnloadViewControllerWithBlock:^{
                    //  卸载 ProjectController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 ProjectController对象
                [self lycHolyAddViewController:self.projectController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleSmart:
        {
            //  隐藏控制视图
            self.lycHolyControlViewHidden = YES;
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 SmartController对象
                self.smartController = [SmartController LYCControllerXIBWithViewDirectionHorizontal];
                [self.smartController lycUnloadViewControllerWithBlock:^{
                    //  卸载 SmartController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 SmartController对象
                [self lycHolyAddViewController:self.smartController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleStroll:
        {
            //  不隐藏控制视图
            self.lycHolyControlViewHidden = NO;
            
            //  设置按钮状态
            [self lycHolyShowButtoNormalStateAndOthersSelectedStateWithCurrentIdentificationStyle];
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 StrollController对象
                self.strollController = [StrollController LYCControllerXIBWithViewDirectionHorizontal];
                [self.strollController lycUnloadViewControllerWithBlock:^{
                    //  卸载 StrollController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 StrollController对象
                [self lycHolyAddViewController:self.strollController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleFormats:
        {
            //  不隐藏控制视图
            self.lycHolyControlViewHidden = NO;
            
            //  设置按钮状态
            [self lycHolyShowButtoNormalStateAndOthersSelectedStateWithCurrentIdentificationStyle];
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 FormatsController对象
                self.formatsController = [FormatsController LYCControllerXIBWithViewDirectionHorizontal];
                [self.formatsController lycUnloadViewControllerWithBlock:^{
                    //  卸载 FormatsController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 FormatsController对象
                [self lycHolyAddViewController:self.formatsController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleProperty:
        {
            //  不隐藏控制视图
            self.lycHolyControlViewHidden = NO;
            
            //  设置按钮状态
            [self lycHolyShowButtoNormalStateAndOthersSelectedStateWithCurrentIdentificationStyle];
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 PropertyController对象
                self.propertyController = [PropertyController LYCControllerXIBWithViewDirectionHorizontal];
                [self.propertyController lycUnloadViewControllerWithBlock:^{
                    //  卸载 PropertyController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 PropertyController对象
                [self lycHolyAddViewController:self.propertyController];
            }];
        }
            break;
        case LYCHolyIdentificationStyleNews:
        {
            //  隐藏控制视图
            self.lycHolyControlViewHidden = YES;
            
            [self lycHolyLoadViewControllerWithButton:button initialization:^{
                //  初始化 SmartController对象
                self.smartController = [SmartController CustomController];
                [self.smartController lycUnloadViewControllerWithBlock:^{
                    //  卸载 SmartController对象后,加载 IndexController对象
                    [self lycHolyLoadViewControllerWithIdentificationStyle:LYCHolyIdentificationStyleIndex];
                }];
            } complete:^{
                //  加载 SmartController对象
                [self lycHolyAddViewController:self.smartController];
            }];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark - 设置释放事件
- (void)lycHolySystemEventReleaseViewControllerWithIdentificationStyle:(LYCHolyIdentificationStyle)identificationStyle
{
    switch (identificationStyle) {
        case LYCHolyIdentificationStyleIndex:
        {
            LYC__Holy__ViewControllerRelease(self.indexController)
        }
            break;
        case LYCHolyIdentificationStyleBrand:
        {
            LYC__Holy__ViewControllerRelease(self.brandController)
        }
            break;
        case LYCHolyIdentificationStyleLocation:
        {
            LYC__Holy__ViewControllerRelease(self.locationController)
        }
            break;
        case LYCHolyIdentificationStyleProject:
        {
            LYC__Holy__ViewControllerRelease(self.projectController)
        }
            break;
        case LYCHolyIdentificationStyleSmart:
        {
            LYC__Holy__ViewControllerRelease(self.smartController)
        }
            break;
        case LYCHolyIdentificationStyleStroll:
        {
            LYC__Holy__ViewControllerRelease(self.strollController)
        }
            break;
        case LYCHolyIdentificationStyleFormats:
        {
            LYC__Holy__ViewControllerRelease(self.formatsController)
        }
            break;
        case LYCHolyIdentificationStyleProperty:
        {
            LYC__Holy__ViewControllerRelease(self.propertyController)
        }
            break;
        case LYCHolyIdentificationStyleNews:
        {
            LYC__Holy__ViewControllerRelease(self.smartController)
        }
            break;
            
        default:
            break;
    }
}

@end

下面是负责数据源的。

//
//  MainModel.h
//  某项目
//
//  Created by yococo on 3/7/15.
//  Copyright (c) 2015 yococo. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface MainModel : NSObject

+ (NSArray *)controlButtons;

@end

//
//  MainModel.m
//  某项目
//
//  Created by yococo on 3/7/15.
//  Copyright (c) 2015 yococo. All rights reserved.
//

#import "MainModel.h"

#import "LYCHolyButton.h"

@implementation MainModel

+ (NSArray *)controlButtons
{
    NSMutableArray *array = [NSMutableArray array];
    /*********   Add  Start   ********/
    LYCHolyButton *button_index = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(52, 18, 0, 50) identificationStyle:LYCHolyIdentificationStyleIndex];
    [array addObject:button_index];
    button_index = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_brand = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(52, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleBrand];
    button_brand.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_01_半暗.png");
    button_brand.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_01_正常.png");
    [array addObject:button_brand];
    button_brand = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_location = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(183, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleLocation];
    button_location.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_02_半暗.png");
    button_location.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_02_正常.png");
    [array addObject:button_location];
    button_location = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_project = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(321, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleProject];
    button_project.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_03_半暗.png");
    button_project.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_03_正常.png");
    [array addObject:button_project];
    button_project = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_smart = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(455, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleSmart];
    button_smart.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_04_半暗.png");
    button_smart.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_04_正常.png");
    [array addObject:button_smart];
    button_smart = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_stroll = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(592, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleStroll];
    button_stroll.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_05_半暗.png");
    button_stroll.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_05_正常.png");
    [array addObject:button_stroll];
    button_stroll = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_formats = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(725, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleFormats];
    button_formats.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_06_半暗.png");
    button_formats.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_06_正常.png");
    [array addObject:button_formats];
    button_formats = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_property = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(864, 18, 100, 50) identificationStyle:LYCHolyIdentificationStyleProperty];
    button_property.lycHolyImageNormalPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_07_半暗.png");
    button_property.lycHolyImageSelectedPath = LYC__PathFromBundleAppendingPathComponent(@"导航按钮_07_正常.png");
    [array addObject:button_property];
    button_property = nil;
    /*********   Add  End   ********/
    /*********   Add  Start   ********/
    LYCHolyButton *button_news = [LYCHolyButton LycHolyButtonWithFrame:CGRectMake(964, 18, 0, 50) identificationStyle:LYCHolyIdentificationStyleNews];
    [array addObject:button_news];
    button_news = nil;
    /*********   Add  End   ********/
    
    
    return array;
    return nil;
}

@end



已经通过某项目实践过,更新了过一些细节修改。

本设计使用了个人Kit:LYCKit。


作者:木子才

关于 LYCHolyContentController 的使用记录

标签:ios   框架设计   objective-c   

原文地址:http://blog.csdn.net/iamyococo/article/details/44132697

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!