//

//  CHViewController.m

//  SuperDrawingSample

//

//  Created by JaikenLI on 13-11-21.

//  Copyright (c) 2013 lanou. All rights reserved.

//

 

#import "CHViewController.h"

#import "CircleView.h"

#import "TuyaPad.h"

@interfaceCHViewController ()

@property (nonatomic,strong)NSMutableArray *imageList;

 //动态刷新首界面滑动视图的分页符以及contentSize,所有子视图

-(void)reloadData;

//画笔大小内的滑块触发的方法..

-(void)lineWidthFromSlider:(UISlider *)slider;

@end

#define KMainSceneTestControlTag        1001

#define KAboutSceneTestControlTag       1002

#define KEditSceneTestControlTag        1003

#define KLineColorSceneTestControlTag   1004

#define KBgColorSceneTestControlTag     1005

#define KLineWidthSceneTestControlTag   1006

#define KDetailSceneTestControlTag      1007

 

@implementation CHViewController

{

    //画笔大小内的圆形视图

    CircleView *circleView;

}

//七大视图作为本类的属性,便于在类的内部调用

//视图加载完后,添加7大视图容器

- (void)viewDidLoad

{

    [superviewDidLoad];

    self.imageList=[[NSMutableArrayalloc]init];//实例化数组

// Do any additional setup after loading the view, typically from a nib.

    [self.view addSubview:self.mainScene];

    [self.view addSubview:self.aboutScene];

    [self.view addSubview:self.editScene];

    [self.viewaddSubview:self.lineColorScene];

    [self.viewaddSubview:self.bgColorScene];

    [self.viewaddSubview:self.lineWidthScene];

    [self.view addSubview:self.detailScene];

}

 

//当根视图将要显示时会触发这个方法

-(void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    //将首页提前

   // [self.view bringSubviewToFront:self.mainScene];

    [self.viewbringSubviewToFront:self.mainScene];

}

//ios7,隐藏statusBar

-(BOOL)prefersStatusBarHidden

{

    returnYES;

}

 

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

//1,程序启动

//2,程序流程框架

//3,程序界面一致

//程序界面功能

#pragma mark -property methods

-(UIView *)mainScene

{

    //如果不等于空则实例化场景

    if (_mainScene!=Nil) {

        return _mainScene;

    }

   

    _mainScene=[[UIViewalloc]initWithFrame:self.view.bounds];

    _mainScene.backgroundColor=[UIColorwhiteColor];

    //背景颜色

    UIView *bgView=[[UIView alloc]initWithFrame:self.view.bounds];

    bgView.backgroundColor=RGB(189, 186, 255);

    //给视图添加边框

    bgView.layer.borderWidth=1.0f;

    bgView.layer.borderColor=[UIColorblackColor].CGColor;

    [_mainScene addSubview:bgView];

    //2,标题New按钮父视图

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.backgroundColor=[UIColor whiteColor];

    [leftButton setTitle:@"New" forState:UIControlStateNormal];

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=[UIColorblackColor].CGColor;

    leftButton.frame =CGRectMake(0, 0, 64, 64);

    

    [_mainScene addSubview:leftButton];

    

    //3,标题title标签视图

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(63, 0, 194, 64)];

    midLabel.backgroundColor=RGB(159, 235, 204);

    midLabel.text=@"Drawing";

    midLabel.font=[UIFont fontWithName:@"chalkboard se" size:30];

    midLabel.textColor=RGB(248, 109, 204);

    midLabel.textAlignment=NSTextAlignmentCenter;

    midLabel.layer.borderWidth=1.0f;

    midLabel.layer.borderColor=[UIColorblackColor].CGColor;

    [_mainScene addSubview:midLabel];

    //2,标题About按钮父视图

    UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    rightButton.backgroundColor=[UIColor whiteColor];

    [rightButton setTitle:@"About" forState:UIControlStateNormal];

    rightButton.layer.borderWidth=1.0f;

    rightButton.layer.borderColor=[UIColor blackColor].CGColor;

    rightButton.frame =CGRectMake(256, 0, 64, 64);

    [_mainScene addSubview:rightButton];

    

    //分页符

    UIPageControl *pageControl=[[UIPageControlalloc]init];

    pageControl.frame=CGRectMake(0, 460, 320, 20);

    pageControl.numberOfPages=0;

    pageControl.currentPage=0;

    pageControl.tag=10010;

    [_mainScene addSubview:pageControl];

    // 5.滚动视图..

    UIScrollView *scrollView = [[UIScrollView alloc] init];

    scrollView.frame = CGRectMake(10, 74, 300, 386);

    scrollView.backgroundColor = RGB(255, 255, 255);

    scrollView.pagingEnabled = YES;

    scrollView.contentSize = CGSizeZero;

    scrollView.delegate = self;

    scrollView.layer.borderWidth = 1.0f;

    scrollView.layer.borderColor = RGB(0, 0, 0).CGColor;

    scrollView.tag = 10036;

    [_mainScene addSubview:scrollView];

 

    //------------------------------------------------------------------------------------------

    //这里只做第一个页面的固定功能

    //在首次创建界面时,我们会指定好固定事件触发前的固定方法

    //至于另外程序启动后,运行过程中会添加和减少的事件触发的方法,我们会在另外一个"刷新"方法内实现

    //左边按钮功能:

    [leftButton addTarget:self action:@selector(mainSceneToEditScene:) forControlEvents:UIControlEventTouchUpInside];

    //右边按钮功能

    [rightButton addTarget:self action:@selector(mainSceneToAboutScene:) forControlEvents:UIControlEventTouchUpInside];

    

    

    

    //-------------------------------------------------------------------------------------------

    return_mainScene;

}

 

-(UIView *)aboutScene

{

     //如果不等于空则实例化场景

    if (_aboutScene!=Nil) {

        return_aboutScene;

    }

    _aboutScene=[[UIViewalloc]initWithFrame:self.view.bounds];

    _aboutScene.backgroundColor=[UIColorwhiteColor];

    

    CGRect frame=CGRectMake(0, 100, 320, 60);

    UISegmentedControl *testControl=[[UISegmentedControlalloc]initWithFrame:frame];

    testControl.momentary=YES;

    [testControl insertSegmentWithTitle:@"Back"atIndex:0animated:NO];

    testControl.tag=KAboutSceneTestControlTag;

    //添加测试按钮触发的测试方法

    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];

    [_aboutScene addSubview:testControl];

 

    //背景颜色

    UIView *bgView=[[UIView alloc]initWithFrame:self.view.bounds];

    bgView.backgroundColor=RGB(255, 255, 255);

    //给视图添加边框

    bgView.layer.borderWidth=1.0f;

    bgView.layer.borderColor=[UIColorblackColor].CGColor;

    [_aboutScene addSubview:bgView];

    //2,标题Back按钮父视图

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.backgroundColor=[UIColor whiteColor];

    [leftButton setTitle:@"Back" forState:UIControlStateNormal];

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=[UIColorblackColor].CGColor;

    leftButton.frame =CGRectMake(0, 0, 64, 64);

    [_aboutScene addSubview:leftButton];

    

    //3,标题title标签视图

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(63, 0, 257, 64)];

    UILabel *titleTextLabel=[[UILabel alloc]initWithFrame:CGRectMake(64, 0,100, 64)];

    

    titleTextLabel.font=[UIFont fontWithName:@"chalkboard se" size:20];

    [titleTextLabel setText:@"Drawing"];

    titleTextLabel.textColor=RGB(248, 109, 204);

    titleTextLabel.textAlignment=NSTextAlignmentCenter;

    

    [midLabel addSubview:titleTextLabel];

    midLabel.backgroundColor=RGB(159, 235, 204);

    midLabel.textAlignment=NSTextAlignmentCenter;

    midLabel.layer.borderWidth=1.0f;

    midLabel.layer.borderColor=[UIColorblackColor].CGColor;

    [_aboutScene addSubview:midLabel];

    //承载字体的label

    UILabel *textLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 64, 320, 300)];

    textLabel.text=@"hello asf sfsf sfs sfsdf s sdf sdf d     sfd ";

    textLabel.backgroundColor=[UIColor whiteColor];

    [_aboutScene addSubview:textLabel];

    //--------------------------------------------------------------------------------------

    //"返回"按钮功能

     [leftButton addTarget:self action:@selector(aboutSceneBackMainScene:) forControlEvents:UIControlEventTouchUpInside];

    

    

    

    //--------------------------------------------------------------------------------------

    return_aboutScene;

}

 

-(UIView *)editScene

{

    //如果不等于空则实例化场景

    if (_editScene!=Nil) {

        return _editScene;

    }

    _editScene=[[UIViewalloc]initWithFrame:self.view.bounds];

    _editScene.backgroundColor=[UIColorwhiteColor];

    ///////////////////////////////////////////

    //背景颜色

    UIView *View=[[UIView alloc]initWithFrame:self.view.bounds];

    View.backgroundColor=RGB(189, 186, 255);

    //给视图添加边框

    View.layer.borderWidth=1.0f;

    View.layer.borderColor=[UIColorblackColor].CGColor;

    [_editScene addSubview:View];

    //2,标题Back按钮父视图

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.backgroundColor=[UIColor whiteColor];

    [leftButton setTitle:@"Back" forState:UIControlStateNormal];

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=[UIColorblackColor].CGColor;

    leftButton.frame =CGRectMake(0, 0, 64, 64);

   

    [_editScene addSubview:leftButton];

    

    //3,标题Save按钮父视图

    UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    rightButton.backgroundColor=[UIColor whiteColor];

    [rightButton setTitle:@"Save" forState:UIControlStateNormal];

    rightButton.layer.borderWidth=1.0f;

    rightButton.layer.borderColor=[UIColor blackColor].CGColor;

    rightButton.frame =CGRectMake(256, 0, 64, 64);

   

    [_editScene addSubview:rightButton];

 

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(63, 0, 194, 64)];

    midLabel.backgroundColor=RGB(159, 235, 204);

    midLabel.layer.borderWidth=1.0f;

    midLabel.layer.borderColor=[UIColorblackColor].CGColor;

    midLabel.userInteractionEnabled=YES;

    [_editScene addSubview:midLabel];

    //中间的三个按钮

    UIButton *backgroundButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    backgroundButton.frame=CGRectMake(65, 10, 62, 40);

    backgroundButton.backgroundColor=[UIColor whiteColor];

    backgroundButton.layer.borderWidth=1;

    backgroundButton.layer.borderColor=[UIColor blackColor].CGColor;

    [backgroundButton setTitle:@"背景" forState:UIControlStateNormal];

    [backgroundButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    backgroundButton.titleLabel.font=[UIFont fontWithName:@"chalkboard se" size:13];

    [_editScene addSubview:backgroundButton];

    

    UIButton *midButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    midButton.frame=CGRectMake(129, 10, 62, 40);

    midButton.backgroundColor=[UIColor whiteColor];

    midButton.layer.borderWidth=1;

    midButton.layer.borderColor=[UIColorblackColor].CGColor;

    [midButton setTitle:@"画笔颜色" forState:UIControlStateNormal];

    [midButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

        midButton.titleLabel.font=[UIFont fontWithName:@"chalkboard se" size:13];

    midButton.titleLabel.textColor=[UIColor blackColor];

    

    [_editScene addSubview:midButton];

    

    UIButton *lineWidthButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];

     lineWidthButton.frame= CGRectMake(193, 10, 62, 40);

    lineWidthButton.backgroundColor=[UIColor whiteColor];

    lineWidthButton.layer.borderWidth=1;

    lineWidthButton.layer.borderColor=[UIColor blackColor].CGColor;

    [lineWidthButton setTitle:@"画笔大小" forState:UIControlStateNormal];

    lineWidthButton.titleLabel.textColor=[UIColor blackColor];

   

    [lineWidthButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    lineWidthButton.titleLabel.font=[UIFont fontWithName:@"chalkboard se" size:13];

    [_editScene addSubview:lineWidthButton];

 //------------------------------------------------------------------------------------------

    //返回按钮功能

     [leftButton addTarget:self action:@selector(editSceneBackMainScene:) forControlEvents:UIControlEventTouchUpInside];

    //保存按钮功能

     [rightButton addTarget:self action:@selector(editSceneBackMainScene:) forControlEvents:UIControlEventTouchUpInside];

    //背景颜色按钮的功能

    [backgroundButton addTarget:self action:@selector(editSceneToBgColorScene:) forControlEvents:UIControlEventTouchUpInside];

    //画笔颜色按钮的功能

    [midButton addTarget:self action:@selector(editSceneToLineColorScene:) forControlEvents:UIControlEventTouchUpInside];

    //画笔大小按钮的功能

     [lineWidthButton addTarget:self action:@selector(editSceneToLineWidthScene:) forControlEvents:UIControlEventTouchUpInside];

    

    

    //-------------------------------------------------------------------------------------------------------------

    TuyaPad *pad=[[TuyaPadalloc]initWithFrame:CGRectMake(10, 74, 300, 385)];

    pad.backgroundColor=[UIColorwhiteColor];

    pad.layer.borderWidth=1;

    pad.layer.borderColor=[UIColorblackColor].CGColor;

    pad.tag=10086;

    [_editScene addSubview:pad];

 

    return_editScene;

}

 

-(UIView *)lineColorScene

      //如果不等于空则实例化场景

    if (_lineColorScene!=Nil) {

        return_lineColorScene;

    }

    _lineColorScene=[[UIView alloc]initWithFrame:self.view.bounds];    

    

    _lineColorScene.frame=self.view.bounds;

    _lineColorScene.backgroundColor=[UIColorclearColor];

    ////////////////////////////

    //1,灰色半透明视图

    

    UIView *  bgView=[[UIView alloc]initWithFrame:self.view.bounds];

    bgView.backgroundColor=[UIColor grayColor];

    bgView.alpha=0.75f;

    [_lineColorScene addSubview:bgView];

    //2,中间白色提醒背景

    UIView *middleView=[[UIView alloc]initWithFrame:CGRectMake(40, 150, 240, 180)];

    middleView.backgroundColor=[UIColor whiteColor];

    middleView.layer.borderWidth=1.0f;

    middleView.layer.borderColor=RGB(0, 0, 0).CGColor;

    //2.1 ,,取消按钮

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.frame=CGRectMake(0, 0,70, 32);

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=RGB(0, 0, 0).CGColor;

    [leftButton setTitle:@"取消" forState:UIControlStateNormal];

    [leftButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    

    [middleView addSubview:leftButton];

    //2.2 中间的label

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(69, 0, 102, 32)];

    midLabel.text=@"画笔颜色";

    midLabel.textAlignment=NSTextAlignmentCenter;

    midLabel.layer.borderColor=RGB(0, 0, 0).CGColor;

    midLabel.layer.borderWidth=1.0f;

    [middleView addSubview:midLabel];

    //2.3 右边的完成按钮

    UIButton *OkButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    OkButton.frame=CGRectMake(170, 0,70, 32);

    OkButton.layer.borderWidth=1.0f;

    OkButton.layer.borderColor=RGB(0, 0, 0).CGColor;

    [OkButton setTitle:@"完成"forState:UIControlStateNormal];

    [OkButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

   

    [middleView addSubview:OkButton];

    

    

    //三个滑块属性设置

    UISlider *sliderR=[[UISlider alloc]initWithFrame:CGRectMake(10, 32, 155, 49)];

    sliderR.minimumTrackTintColor=[UIColorredColor];

    sliderR.minimumValue=0;

    sliderR.maximumValue=1;

   

    [middleView addSubview:sliderR];

    

    UISlider *sliderG=[[UISlider alloc]initWithFrame:CGRectMake(10, 71, 155, 49)];

    sliderG.minimumTrackTintColor=[UIColorgreenColor];

    sliderG.minimumValue=0;

    sliderG.maximumValue=1;

    [middleView addSubview:sliderG];

    

    UISlider *sliderB=[[UISlider alloc]initWithFrame:CGRectMake(10, 114, 155, 49)];

    sliderB.minimumTrackTintColor=[UIColorblueColor];

    sliderB.minimumValue=0;

    sliderB.maximumValue=1;

    [middleView addSubview:sliderB];

     sliderR.tag=111;

    sliderG.tag=222;

    sliderB.tag=333;

    //三个滑块后面的颜色标签

    UILabel *Rlabel=[[UILabel alloc]initWithFrame:CGRectMake(170, 40, 45, 30)];

    Rlabel.backgroundColor=[UIColor redColor];

    Rlabel.layer.borderWidth=1;

    Rlabel.layer.borderColor=[UIColorblackColor].CGColor;

    Rlabel.text=@"red";

    Rlabel.textColor=[UIColor whiteColor];

    Rlabel.textAlignment=NSTextAlignmentCenter;

    Rlabel.font=[UIFont fontWithName:@"chalkBoard se" size:14];

    [middleView addSubview:Rlabel];

    

    UILabel *Glabel=[[UILabel alloc]initWithFrame:CGRectMake(170, 79, 45, 30)];

    Glabel.backgroundColor=[UIColor greenColor];

    Glabel.layer.borderWidth=1;

    Glabel.layer.borderColor=[UIColorblackColor].CGColor;

    Glabel.text=@"green";

    Glabel.textColor=[UIColor whiteColor];

    Glabel.textAlignment=NSTextAlignmentCenter;

    Glabel.font=[UIFont fontWithName:@"chalkBoard se" size:14];

    [middleView addSubview:Glabel];

 

    UILabel *Blabel=[[UILabel alloc]initWithFrame:CGRectMake(170, 118, 45, 30)];

    Blabel.backgroundColor=[UIColor blueColor];

    Blabel.layer.borderWidth=1;

    Blabel.layer.borderColor=[UIColorblackColor].CGColor;

    Blabel.text=@"blue";

    Blabel.textColor=[UIColor whiteColor];

    Blabel.textAlignment=NSTextAlignmentCenter;

    Blabel.font=[UIFont fontWithName:@"chalkBoard se" size:14];

    [middleView addSubview:Blabel];

    //---------------------------------------------------------------------------

    //取消按钮

    [leftButton addTarget:self action:@selector(lineColorSceneBackEditScene:) forControlEvents:UIControlEventTouchUpInside];

    //完成按钮

     [OkButton addTarget:self action:@selector(lineColorSceneBackEditScene:) forControlEvents:UIControlEventTouchUpInside];

    //---------------------------------------------------------------------------

 

    [_lineColorScene addSubview:middleView];

    return_lineColorScene;

}

 

 

-(UIView *)bgColorScene

{

     //如果不等于空则实例化场景

    if (_bgColorScene!=Nil) {

        return_bgColorScene;

    }

    _bgColorScene=[[UIViewalloc]initWithFrame:self.view.bounds];

    _bgColorScene.backgroundColor=[UIColorwhiteColor];

    

    ////////////////////////////

    //1,灰色半透明视图

    

    UIView *  bgView=[[UIView alloc]initWithFrame:self.view.bounds];

    bgView.backgroundColor=[UIColor grayColor];

    bgView.alpha=0.75f;

    [_bgColorScene addSubview:bgView];

    //2,中间白色提醒背景

    UIView *middleView=[[UIView alloc]initWithFrame:CGRectMake(40, 150, 240, 180)];

    middleView.backgroundColor=[UIColor whiteColor];

    middleView.layer.borderWidth=1.0f;

    middleView.layer.borderColor=RGB(0, 0, 0).CGColor;

    //2.1 ,,取消按钮

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.frame=CGRectMake(0, 0,70, 32);

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=RGB(0, 0, 0).CGColor;

    [leftButton setTitle:@"取消" forState:UIControlStateNormal];

    [leftButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    

    [middleView addSubview:leftButton];

    //2.2 中间的label

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(70, 0, 100, 32)];

    midLabel.text=@"背景颜色";

    midLabel.textAlignment=NSTextAlignmentCenter;

    midLabel.layer.borderColor=RGB(0, 0, 0).CGColor;

    midLabel.layer.borderWidth=1.0f;

    [middleView addSubview:midLabel];

    //2.3 右边的完成按钮

    UIButton *OkButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    OkButton.frame=CGRectMake(170, 0,70, 32);

    OkButton.layer.borderWidth=1.0f;

    OkButton.layer.borderColor=RGB(0, 0, 0).CGColor;

    [OkButton setTitle:@"完成"forState:UIControlStateNormal];

    [OkButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

      [middleView addSubview:OkButton];

    

    

    //三个滑块属性设置

    UISlider *sliderR=[[UISlider alloc]initWithFrame:CGRectMake(10, 32, 155, 49)];

    sliderR.minimumTrackTintColor=[UIColorredColor];

    sliderR.minimumValue=0;

    sliderR.maximumValue=1;

    sliderR.tag=111;

    [middleView addSubview:sliderR];

    

    UISlider *sliderG=[[UISlider alloc]initWithFrame:CGRectMake(10, 71, 155, 49)];

    sliderG.minimumTrackTintColor=[UIColorgreenColor];

    sliderG.minimumValue=0;

    sliderG.maximumValue=1;

    sliderG.tag=222;

    [middleView addSubview:sliderG];

    

    UISlider *sliderB=[[UISlider alloc]initWithFrame:CGRectMake(10, 114, 155, 49)];

    sliderB.minimumTrackTintColor=[UIColorblueColor];

    sliderB.minimumValue=0;

    sliderB.maximumValue=1;

    sliderB.tag=333;

    [middleView addSubview:sliderB];

    //三个滑块后面的颜色标签

    UILabel *Rlabel=[[UILabel alloc]initWithFrame:CGRectMake(170, 40, 45, 30)];

    Rlabel.backgroundColor=[UIColor redColor];

    Rlabel.layer.borderWidth=1;

    Rlabel.layer.borderColor=[UIColorblackColor].CGColor;

    Rlabel.text=@"red";

    Rlabel.textColor=[UIColor whiteColor];

    Rlabel.textAlignment=NSTextAlignmentCenter;

    Rlabel.font=[UIFont fontWithName:@"chalkBoard se" size:14];

    [middleView addSubview:Rlabel];

    

    UILabel *Glabel=[[UILabel alloc]initWithFrame:CGRectMake(170, 79, 45, 30)];

    Glabel.backgroundColor=[UIColor greenColor];

    Glabel.layer.borderWidth=1;

    Glabel.layer.borderColor=[UIColorblackColor].CGColor;

    Glabel.text=@"green";

    Glabel.textColor=[UIColor whiteColor];

    Glabel.textAlignment=NSTextAlignmentCenter;

    Glabel.font=[UIFont fontWithName:@"chalkBoard se" size:14];

    [middleView addSubview:Glabel];

    

    UILabel *Blabel=[[UILabel alloc]initWithFrame:CGRectMake(170, 118, 45, 30)];

    Blabel.backgroundColor=[UIColor blueColor];

    Blabel.layer.borderWidth=1;

    Blabel.layer.borderColor=[UIColorblackColor].CGColor;

    Blabel.text=@"blue";

    Blabel.textColor=[UIColor whiteColor];

    Blabel.textAlignment=NSTextAlignmentCenter;

    Blabel.font=[UIFont fontWithName:@"chalkBoard se" size:14];

    [middleView addSubview:Blabel];

    

    _bgColorScene.frame=self.view.bounds;

    _bgColorScene.backgroundColor=[UIColorclearColor];

    

    //---------------------------------------------------------------------------

    //取消按钮

    [leftButton addTarget:self action:@selector(bgColorSceneBackEditScene:) forControlEvents:UIControlEventTouchUpInside];

    //完成按钮

    [OkButton addTarget:self action:@selector(bgColorSceneBackEditScene:) forControlEvents:UIControlEventTouchUpInside];

 

    //---------------------------------------------------------------------------

    

 

    [_bgColorScene addSubview:middleView];

    return_bgColorScene;

}

 

-(UIView *)lineWidthScene

{

     //如果不等于空则实例化场景

    if (_lineWidthScene!=Nil) {

        return_lineWidthScene;

    }

    _lineWidthScene=[[UIViewalloc]initWithFrame:self.view.bounds];

    _lineWidthScene.backgroundColor=[UIColorclearColor];

    ////////////////////////////

    //1,灰色半透明视图

    

    UIView *  bgView=[[UIView alloc]initWithFrame:self.view.bounds];

    bgView.backgroundColor=[UIColor grayColor];

    bgView.alpha=0.75f;

    [_lineWidthScene addSubview:bgView];

    //2,中间白色提醒背景

    UIView *middleView=[[UIView alloc]initWithFrame:CGRectMake(40, 150, 240, 180)];

    middleView.backgroundColor=[UIColor whiteColor];

    middleView.layer.borderWidth=1.0f;

    middleView.layer.borderColor=RGB(0, 0, 0).CGColor;

    //brown背景

    UIView *brownView=[[UIView alloc]initWithFrame:CGRectMake(0, 32, 240, 148)];

    brownView.backgroundColor=[UIColor brownColor];

    brownView.layer.borderWidth=1.0f;

    brownView.layer.borderColor=RGB(0, 0, 0).CGColor;

    [middleView addSubview:brownView];

    

    //2.1 ,,取消按钮

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.frame=CGRectMake(0, 0,70, 32);

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=RGB(0, 0, 0).CGColor;

    [leftButton setTitle:@"取消" forState:UIControlStateNormal];

    [leftButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

       [middleView addSubview:leftButton];

    //2.2 中间的label

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(70, 0, 100, 32)];

    midLabel.text=@"画笔大小";

    midLabel.textAlignment=NSTextAlignmentCenter;

    midLabel.layer.borderColor=RGB(0, 0, 0).CGColor;

    midLabel.layer.borderWidth=1.0f;

    [middleView addSubview:midLabel];

    //2.3 右边的完成按钮

    UIButton *OkButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    OkButton.frame=CGRectMake(170, 0,70, 32);

    OkButton.layer.borderWidth=1.0f;

    OkButton.layer.borderColor=RGB(0, 0, 0).CGColor;

    [OkButton setTitle:@"完成"forState:UIControlStateNormal];

    [OkButton setTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

  

    [middleView addSubview:OkButton];

    

    UISlider *lineWidthSlider;

    //三个滑块属性设置

    lineWidthSlider=[[UISlider alloc]initWithFrame:CGRectMake(10, 82, 155, 49)];

    lineWidthSlider.minimumTrackTintColor=[UIColor redColor];

    lineWidthSlider.minimumValue=5;

    lineWidthSlider.maximumValue=10;

    lineWidthSlider.tag=555;

    [lineWidthSlider addTarget:self action:@selector(lineWidthFromSlider:) forControlEvents:UIControlEventValueChanged];

    

    [middleView addSubview:lineWidthSlider];

    

    //添加画圆视图..

    circleView=[[CircleViewalloc]initWithFrame:CGRectMake(170,CGRectGetMidY(middleView.bounds), 25, 25)];

    circleView.backgroundColor=[UIColorclearColor];

    [middleView addSubview: circleView];

    //---------------------------------------------------------------------------

    //取消按钮

    [leftButton addTarget:self action:@selector(lineWidthSceneBackEditScene:) forControlEvents:UIControlEventTouchUpInside];

    //完成按钮

     [OkButton addTarget:self action:@selector(lineWidthSceneBackEditScene:) forControlEvents:UIControlEventTouchUpInside];

    

    //---------------------------------------------------------------------------

 

    

    [_lineWidthScene addSubview:middleView];

    return_lineWidthScene;

}

 

-(UIView *)detailScene

{

      //如果不等于空则实例化场景

    if (_detailScene!=Nil) {

        return_detailScene;

    }

    _detailScene=[[UIViewalloc]initWithFrame:self.view.bounds];

    _detailScene.backgroundColor=[UIColorwhiteColor];

    

    //背景颜色

    UIView *bgView=[[UIView alloc]initWithFrame:self.view.bounds];

    bgView.backgroundColor=RGB(189, 186, 255);

    //给视图添加边框

    bgView.layer.borderWidth=1.0f;

    bgView.layer.borderColor=[UIColorblackColor].CGColor;

    [_detailScene addSubview:bgView];

    //2,标题New按钮父视图

    UIButton *leftButton=[UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    leftButton.backgroundColor=[UIColor whiteColor];

    [leftButton setTitle:@"Back" forState:UIControlStateNormal];

    leftButton.layer.borderWidth=1.0f;

    leftButton.layer.borderColor=[UIColorblackColor].CGColor;

    leftButton.frame =CGRectMake(0, 0, 64, 64);

    

    [_detailScene addSubview:leftButton];

    

    //3,标题title标签视图

    UILabel *midLabel=[[UILabel alloc]initWithFrame:CGRectMake(63, 0, 194, 64)];

    midLabel.backgroundColor=RGB(159, 235, 204);

    

    midLabel.layer.borderWidth=1.0f;

    midLabel.layer.borderColor=[UIColorblackColor].CGColor;

    [_detailScene addSubview:midLabel];

    //2,标题About按钮父视图

    UIButton *rightButton=[UIButton buttonWithType:UIButtonTypeRoundedRect];

    rightButton.backgroundColor=[UIColor whiteColor];

    [rightButton setTitle:@"Delete" forState:UIControlStateNormal];

    rightButton.layer.borderWidth=1.0f;

    rightButton.layer.borderColor=[UIColor blackColor].CGColor;

    rightButton.frame =CGRectMake(256, 0, 64, 64);

    [_detailScene addSubview:rightButton];

    

    

  //----------------------------------------------------

    [leftButton addTarget:self action:@selector(detailSceneBackMainScene:) forControlEvents:UIControlEventTouchUpInside];

    //右边按钮功能

    [rightButton addTarget:self action:@selector(detailSceneBackMainScene:) forControlEvents:UIControlEventTouchUpInside];

    

     //----------------------------------------------------

    UIImageView *whiteView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 74, 300, 385)];

    whiteView.backgroundColor=[UIColor whiteColor];

    whiteView.layer.borderWidth=1;

    whiteView.layer.borderColor=[UIColorblackColor].CGColor;

    [_detailScene addSubview:whiteView];

    

    return_detailScene;

}

 

//

#pragma mark -mainScene         出口方法

-(void)mainSceneToAboutScene:(id)sender

{

    //将关于界面提前

    [self.viewbringSubviewToFront:self.aboutScene];

}

-(void)mainSceneToEditScene:(id)sender

{

    //将编辑界面提前

    [self.viewbringSubviewToFront:self.editScene];

}

-(void)mainSceneToDetailScene:(id)sender

{

    //UIScrollView *scrollView= 10036;

     UIPageControl *pageControl=(UIPageControl *)[self.mainScene viewWithTag:10010];

   NSInteger index= pageControl.currentPage;

    ((UIImageView *)[self.detailScene.subviews lastObject]).image= self.imageList[index];

    //将详细界面提前

    [self.viewbringSubviewToFront:self.detailScene];

    

}

 

#pragma mark -aboutScene        出口方法

-(void)aboutSceneBackMainScene:(id)sender

{

    //返回主界面

    [self.viewbringSubviewToFront:self.mainScene];

}

 

#pragma mark -editScene         出口方法

-(void)editSceneToLineColorScene:(id)sender

{

    //lineColor界面提前

    [self.viewbringSubviewToFront:self.lineColorScene];

}

 

-(void)editSceneToBgColorScene:(id)sender

{

    //BgColorScene界面提前

    [self.viewbringSubviewToFront:self.bgColorScene];

}

 

-(void)editSceneToLineWidthScene:(id)sender

{

    //LineWidthScene提前

    [self.viewbringSubviewToFront:self.lineWidthScene];

}

 

-(void)editSceneBackMainScene:(id)sender

{

    //MainScene提前

    [self.viewbringSubviewToFront:self.mainScene];

    //

    if (sender==Nil) {

        return;

    }

    UIButton *button=(UIButton *)sender;//强转之后于智能提示

    if ([button.titleLabel.text isEqual:@"Save"]) {

        //获取绘画板视图..

        TuyaPad *pad=(TuyaPad *)[self.editScene viewWithTag:10086];

        //对绘画板视图进行截图

        UIImage *padScreen=[pad getImageFromCurrentContext];

        //添加到数组

        [self.imageList addObject:padScreen];

       //刷新

        [self reloadData];

        

    }

    

}

 

 

#pragma mark -lineColorScene    出口方法

-(void)lineColorSceneBackEditScene:(id)sender

{

    //editScene提前

   

    UIButton *button=(UIButton *)sender;

 if ([button.titleLabel.text isEqualToString:@"完成"]) {

      //获取三个slider

    UISlider *redslider=(UISlider *)[[self lineColorScene] viewWithTag:111];

    UISlider *greenslider=(UISlider *)[[self lineColorScene] viewWithTag:222];

    UISlider *blueslider=(UISlider *)[[self lineColorScene] viewWithTag:333];

    //设置画笔颜色

    TuyaPad *pad=(TuyaPad *)[self.editSceneviewWithTag:10086];

    pad.lineColor=[UIColor colorWithRed:redslider.value green:greenslider.value blue:blueslider.value alpha:1.0];

    }

    [self.viewbringSubviewToFront:self.editScene];

 

}

 

#pragma mark -bgColorScene      出口方法

-(void)bgColorSceneBackEditScene:(id)sender

{

    UIButton *button=(UIButton *)sender;

    if ([button.titleLabel.text isEqualToString:@"完成"]) {

        //editScene提前

               //获取三个slider

        UISlider *redslider=(UISlider *)[[self bgColorScene] viewWithTag:111];

        UISlider *greenslider=(UISlider *)[[self bgColorScene] viewWithTag:222];

        UISlider *blueslider=(UISlider *)[[self bgColorScene] viewWithTag:333];

        //获取涂鸦板

        TuyaPad *pad=(TuyaPad *)[self.editScene viewWithTag:10086];

        

        pad.backgroundColor=[UIColor colorWithRed:redslider.value green:greenslider.value blue:blueslider.value alpha:1.0];

  

    }

    [self.viewbringSubviewToFront:self.editScene];

 

 }

 

#pragma mark -lineWidthScene    出口方法

-(void)lineWidthSceneBackEditScene:(id)sender

{

    

    UIButton *button=(UIButton *)sender;

    if ([button.titleLabel.text isEqualToString:@"完成"]) {

        //editScene提前

        //获取三个slider

        UISlider *redslider=(UISlider *)[[self lineWidthScene] viewWithTag:555];

        

        //获取涂鸦板

        TuyaPad *pad=(TuyaPad *)[self.editScene viewWithTag:10086];

        pad.lineWidth=redslider.value;

        

    }

 

    //editScene提前

    [self.viewbringSubviewToFront:self.editScene];

}

 

#pragma mark -detailScene       出口方法

-(void)detailSceneToEditScene:(id)sender

{

    //editScene提前

    [self.viewbringSubviewToFront:self.editScene];

    

}

 

-(void)detailSceneBackMainScene:(id)sender

{

     UIButton * button=(UIButton *)sender;

    if ([button.titleLabel.text isEqualToString:@"Delete"])

    {

     //mainScene提前

    UIPageControl *pageControl=(UIPageControl *)[self.mainScene viewWithTag:10010];

    NSInteger index= pageControl.currentPage;

    [self.imageList removeObjectAtIndex: index];

    [selfreloadData];

    }

    [self.viewbringSubviewToFront:self.mainScene];

}

 

#pragma mark -私有方法

-(void)lineWidthFromSlider:(UISlider *)slider

{

     circleView.radius=slider.value;

}

#pragma mark --测试程序流程的方法

-(void)testSegue:(UISegmentedControl *)testControl

{

    switch (testControl.tag) {

        caseKMainSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                    [self mainSceneToEditScene:nil];

                    break;

                }

                case 1:

                {

                    break;

                }

                case 2:

                {

                    [self mainSceneToAboutScene:nil];

                    break;

                }

                    

                default:

                    break;

            }

             break;

        }

            

        caseKAboutSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                    [self aboutSceneBackMainScene:nil];

                    break;

                }

                case 1:

                {

                    

                    break;

                }

                case 2:

                {

                    

                    break;

                }

                    

                default:

                    break;

            }

            break;

        }

        caseKEditSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                    [self editSceneBackMainScene:nil];

                    break;

                }

                case 1:

                {

                    [self editSceneToBgColorScene:nil];

                    break;

                }

                case 2:

                {

                    [self editSceneToLineColorScene:nil];

                    break;

                }

                case 3:

                {

                    [self editSceneToLineWidthScene:nil];

                    break;

                }

                  

                default:

                    break;

            }

            break;

        }

            

        caseKLineColorSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                   [selflineColorSceneBackEditScene:nil];

                    break;

                }

                case 1:

                {

                   

                    break;

                }

                case 2:

                {

                    [selflineColorSceneBackEditScene:nil];

                    break;

                }

                    

                default:

                    break;

            }

            break;

        }

        caseKLineWidthSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                    [selflineWidthSceneBackEditScene:nil];

 

                    break;

                }

                case 1:

                {

                    

                    break;

                }

                case 2:

                {

                    [selflineWidthSceneBackEditScene:nil];

                    break;

                }

                    

                default:

                    break;

            }

            break;

        }

            

        caseKBgColorSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                    [self bgColorSceneBackEditScene:nil];

                    break;

                }

                case 1:

                {

                    

                    break;

                }

                case 2:

                {

                   [selfbgColorSceneBackEditScene:nil];

                    break;

                }

                    

                default:

                    break;

            }

            break;

        }

        caseKDetailSceneTestControlTag:

        {

            switch (testControl.selectedSegmentIndex) {

                case 0:

                {

                    [self detailSceneToEditScene:nil];

                    break;

                }

                case 1:

                {

                    

                    break;

                }

                case 2:

                {

                    [self detailSceneBackMainScene:nil];

                    break;

                }

                    

                default:

                    break;

            }

            break;

        }

 

 

            

        default:

            break;

            

    }

}

 

-(void)reloadData

{

    //分页符

    {

    UIPageControl *pageControl=(UIPageControl *)[self.mainScene viewWithTag:10010];

    pageControl.currentPage=0;

    pageControl.numberOfPages=self.imageList.count;

    }

    //内容大小

   

    //获取滚动视图

        UIScrollView *scrollView=(UIScrollView *)[self.mainScene viewWithTag:10036];

    //获取滚动视图的宽度

        CGFloat width=CGRectGetWidth(scrollView.bounds);

                    //真实内容宽度

        width*=self.imageList.count;

        CGFloat height=0.0f;

        scrollView.contentSize=CGSizeMake(width, height);

    

    //所有子视图

    {

    //删除所有子视图

        while (scrollView.subviews.count!=0) {

            UIImageView *itemView= (UIImageView *)[scrollView.subviews lastObject];

            //移除子视图

            [itemView removeFromSuperview];

        }

        

        for (UIImage *image in self.imageList) {

            UIImageView *imageView=[[UIImageView alloc]initWithFrame:scrollView.bounds];

            imageView.image=image;

            CGFloat midx=[self.imageList indexOfObject:image]*CGRectGetWidth(scrollView.bounds)+CGRectGetWidth(scrollView.bounds)/2.0f;

            CGFloat midy=CGRectGetHeight(scrollView.bounds)/2.0f;

            imageView.center=CGPointMake(midx, midy);

            imageView.userInteractionEnabled=YES;

            //单击手机识别器

            UITapGestureRecognizer *tap=[[UITapGestureRecognizeralloc]init];

            //设置手势识别器需要的点击次数

            tap.numberOfTapsRequired=1;

            //设置手势识别器手指个数

            tap.numberOfTouchesRequired=1;

            //添加触发方法

            [tap addTarget:self action:@selector(mainSceneToDetailScene:)];

            //将手势识别器添加到图片视图上

            [imageView addGestureRecognizer:tap];

            //将图片视图添加到滚动视图上

            [scrollView addSubview:imageView];

        }

    

    }

}

 

#pragma mark uiscrollview

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

{

//可通过当前窗口对于坐标原点的偏移量计算页码

    CGPoint offset=scrollView.contentOffset;

    //计算页码

    NSInteger pageIndex=offset.x/CGRectGetWidth(scrollView.bounds);

    UIPageControl *page=(UIPageControl *)[self.mainSceneviewWithTag:10010];

    page.currentPage=pageIndex;

}

@end