//

//  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

IOS 作业项目(4)步步完成 画图 程序(剧终)的更多相关文章

  1. IOS 作业项目(4)步步完成 画图 程序(中续)

    一,程序布局整理 前言://1,程序启动//2,程序流程框架//3,程序界面一致//4,程序界面功能, //这里只做页面的固定功能, //在首次创建界面时,我们会指定好固定事件触发前的固定方法 //至 ...

  2. IOS 作业项目(4)步步完成 画图 程序(问题处理)终结

    一,解决换色程序崩溃问题 程序崩溃是因为颜色的内存被释放,添加如下类的内容即可 @implementation TuyaPath - (id)init { self = [super init]; i ...

  3. IOS 作业项目(4)步步完成 画图 程序(中)

    一,承接上文,继续本文  [UIButton buttonWithType:UIButtonTypeRoundedRect]; 如此声明的按钮才会有点击闪动的效果!如果直接frame方式声明就不会有. ...

  4. IOS 作业项目(4)步步完成 画图 程序(上)

    先上流程图

  5. IOS 作业项目(2) 画图(保存,撤销,笔粗细设定功能)

    先上效果图

  6. IOS 作业项目 TableView两个section中cell置顶功能实现

    点击cell会置顶,其他的下移

  7. IOS 作业项目(3) 霓虹灯效果

    先上效果图 #import "CHViewController.h"@interface CHViewController (){    int i;    int j;}@pro ...

  8. IOS 作业项目(1) 关灯游戏 (百行代码搞定)

    1,准备工作,既然要开关灯,就需要确定灯的灯的颜色状态 首先想到的是扩展UIColor

  9. java画图程序_图片用字母画出来_源码发布_版本二

    在上一个版本:java画图程序_图片用字母画出来_源码发布 基础上,增加了图片同比例缩放,使得大像素图片可以很好地显示画在Notepad++中. 项目结构: 运行效果1: 原图:http://imag ...

随机推荐

  1. JFrame背景

    1.引言 在了解了JFrame面板的相关知识后,我们可以选择在RootPane根面板或LayeredPane面板中设置背景图案. 2.方法 对于大小固定的窗口背景设置如下: //导入图案 ImageI ...

  2. Java开发 Eclipse使用技巧(转)

    1.如何设置默认的代码目录为src,默认的输出目录为bin? window->Preferences->java->Build Path中,右侧选择Folders就可以 2.如何为快 ...

  3. 使用strace工具故障排查的5种简单方法

    使用strace工具故障排查的5种简单方法 本文源自5 simple ways to troubleshoot using strace strace 是一个非常简单的工具,用来跟踪可执行程序的系统调 ...

  4. shell学习记录001-知识点储备

    1.BASH(bourne again shell ) cmd1 ;cmd2等同于 cmd1 cmd2 2.echo music; 中的分号不被打印出,因为分号默认为命令定界符号 3.利用pgrep找 ...

  5. mysqldump使用语法

    复制代码 代码如下: mysqldump -u user -p db tab1 tab2 > db.sql   恢复 复制代码 代码如下: mysql -u user -p db < db ...

  6. ie8解决F12问题

    工作中,突然电脑上的ie8按F12掉不出来了,一直显示最小化.于是在网上找了很多方法,按这种方法可以解决问题. 1.cmd+r,输入regedit,调出 注册表编辑器. 2.HKEY_CURRENT_ ...

  7. 佳佳的魔法药水 (vijos 1285)

    题目大意: 给出N种药水的价格,然后给出一些形如A B C 的关系,表示 A药水+B药水 可以组合出 C药水(保证 A+B 不会得到多种药水). 要求得到1号药水的最少花费和相应的方案数. N< ...

  8. NOIP 2001解题报告

    第一题:  有形如:ax3+bx2+cx+d=0  这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d  均为实数),并约定该方程存在三个不同实根(根的范围在-100至100之间),且根与 ...

  9. JQuery 来获取数据c#中的JSON数据

    C# 后台 (JSONHandler.ashx) <%@ WebHandler Language="C#" Class="JSONHandler" %&g ...

  10. php 判断是否 是手机访问

    //判断是否属手机 function is_mobile() { $user_agent = $_SERVER['HTTP_USER_AGENT']; $mobile_agents = Array(& ...