DatePickerIos.mm

你的財神爺發表於2018-06-14

#import <UIKit/UIKit.h>

#import "RootViewController.h"

#import "DatePickerIos.h"

#import "DatePickerView.h"


@interface DatePickerViewController : UIViewController


- (void)show:(std::string)date;


@end


@interface DatePickerViewController () <DatePickerViewDelegate>

@property DatePickerView *dateView;

@end


@implementation DatePickerViewController


- (void)initSelf

{

    DatePickerView *dateView = [[DatePickerView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 300)];

    dateView.delegate = self;

    dateView.title = @"請選擇時間";

    dateView.cancel = @"取消";

    dateView.confirm = @"確認";

    //    dateView.isSlide = NO;

    //    dateView.date = @"2017-03-23 12:43";

    //    dateView.minuteInterval = 1;

    [self.view addSubview:dateView];

    self.dateView = dateView;

}


// 顯示

- (void)show:(std::string)date

{

    if(self.dateView != nil){

        [UIView animateWithDuration:0.3 animations:^{

            self.dateView.frame = CGRectMake(0, self.view.frame.size.height - 300, self.view.frame.size.width, 300);

             NSLog(@"dateView show 顯示");

            [self.dateView show];

        }];

    }

}


#pragma mark - THDatePickerViewDelegate

/**

 儲存按鈕代理方法

 

 @param timer 選擇的資料

 */

- (void)datePickerViewSaveBtnClickDelegate:(NSString *)timer {

    NSLog(@"儲存點選");

    if (self.dateView == nil) {

        NSLog(@"self.dateView == nil");

        return;

    }

    std::string date = [timer UTF8String];

    cocos2d::Director::getInstance()->getEventDispatcher()->dispatchCustomEvent("DataPickerEvent",&date);

    [UIView animateWithDuration:0.3 animations:^{

        self.dateView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 300);

        }

                     completion:^(BOOL finished){

                         [self.dateView removeFromSuperview];

                         self.dateView = nil;

                     }

     ];

}


/**

 取消按鈕代理方法

 */

- (void)datePickerViewCancelBtnClickDelegate {

    NSLog(@"取消點選");

    if (self.dateView == nil) {

        NSLog(@"self.dateView == nil");

        return;

    }

    [UIView animateWithDuration:0.3 animations:^{

        self.dateView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 300);

    }completion:^(BOOL finished){

        [self.dateView removeFromSuperview];

        self.dateView = nil;

    }];

}


@end


DatePickerIos *DatePickerIos::datePickerIos = nullptr;


DatePickerIos *DatePickerIos::getInstance()

{

    if(datePickerIos == nullptr)

    {

        datePickerIos = new DatePickerIos();

    }

    

    return datePickerIos;

}


void DatePickerIos::setViewController(void* viewController)

{

    this->viewController = viewController;

    

    datePickerViewController = [[DatePickerViewController alloc] initWithNibName:nil bundle:nil];

    //[((DatePickerViewController*)datePickerViewController) initSelf];

    [((RootViewController*)viewController).view addSubview:((DatePickerViewController*)datePickerViewController).view];

}


void DatePickerIos::show(std::string date)

{

    [((DatePickerViewController*)datePickerViewController) initSelf];

    [((DatePickerViewController*)datePickerViewController) show:date];

}