先上流程图

一,首先在.h中声明UIViewController类属性

//界面
@property(nonatomic,strong)UIView *mainScene;
@property(nonatomic,strong)UIView *aboutScene;
@property(nonatomic,strong)UIView *editScene;
@property(nonatomic,strong)UIView *lineColorScene;
@property(nonatomic,strong)UIView *bgColorScene;
@property(nonatomic,strong)UIView *lineWidthScene;
@property(nonatomic,strong)UIView *detailScene;
二,在.m文件中做好初始化和框架

//七大视图作为本类的属性,便于在类的内部调用
//视图加载完后,添加7大视图容器
- (void)viewDidLoad
{
    [super viewDidLoad];
    // 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.view addSubview:self.lineColorScene];
    [self.view addSubview:self.bgColorScene];
    [self.view addSubview:self.lineWidthScene];
    [self.view addSubview:self.detailScene];
}

//当根视图将要显示时会触发这个方法
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //将首页提前
    [self.view bringSubviewToFront:self.mainScene];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -property methods
-(UIView *)mainScene
{
    //如果不等于空 则实例化场景
    if (_mainScene!=Nil) {
        return _mainScene;
    }
   
    _mainScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _mainScene.backgroundColor=[UIColor whiteColor];
    //实例化测试控制按钮
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"About" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"Drawing" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"New" atIndex:0 animated:NO];
    testControl.tag=KMainSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_mainScene addSubview:testControl];
    return _mainScene;
}

-(UIView *)aboutScene
{
     //如果不等于空 则实例化场景
    if (_aboutScene!=Nil) {
        return _aboutScene;
    }
    _aboutScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _aboutScene.backgroundColor=[UIColor whiteColor];
    
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"Drawing" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"Back" atIndex:0 animated:NO];
    testControl.tag=KAboutSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_aboutScene addSubview:testControl];
    return _aboutScene;
}

-(UIView *)editScene
{
    //如果不等于空 则实例化场景
    if (_editScene!=Nil) {
        return _editScene;
    }
    _editScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _editScene.backgroundColor=[UIColor grayColor];
    
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"背景" atIndex:0 animated:NO];
     [testControl insertSegmentWithTitle:@"画笔颜色" atIndex:0 animated:NO];
     [testControl insertSegmentWithTitle:@"画笔大小" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"Back" atIndex:0 animated:NO];
    testControl.tag=KEditSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_editScene addSubview:testControl];

return _editScene;
}

-(UIView *)lineColorScene
{
      //如果不等于空 则实例化场景
    if (_lineColorScene!=Nil) {
        return _lineColorScene;
    }
    _lineColorScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _lineColorScene.backgroundColor=[UIColor blueColor];
    
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"完成" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"画笔颜色" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"取消" atIndex:0 animated:NO];
    testControl.tag=KLineColorSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_lineColorScene addSubview:testControl];

return _lineColorScene;
}

-(UIView *)bgColorScene
{
     //如果不等于空 则实例化场景
    if (_bgColorScene!=Nil) {
        return _bgColorScene;
    }
    _bgColorScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _bgColorScene.backgroundColor=[UIColor greenColor];
    
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"完成" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"背景颜色" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"取消" atIndex:0 animated:NO];
    testControl.tag=KBgColorSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_bgColorScene addSubview:testControl];

return _bgColorScene;
}

-(UIView *)lineWidthScene
{
     //如果不等于空 则实例化场景
    if (_lineWidthScene!=Nil) {
        return _lineWidthScene;
    }
    _lineWidthScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _lineWidthScene.backgroundColor=[UIColor brownColor];
    
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"完成" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"画笔大小" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"取消" atIndex:0 animated:NO];
    testControl.tag=KLineWidthSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_lineWidthScene addSubview:testControl];

return _lineWidthScene;
}

-(UIView *)detailScene
{
      //如果不等于空 则实例化场景
    if (_detailScene!=Nil) {
        return _detailScene;
    }
    _detailScene=[[UIView alloc]initWithFrame:self.view.bounds];
    _detailScene.backgroundColor=[UIColor yellowColor];
    
    CGRect frame=CGRectMake(0, 100, 320, 60);
    UISegmentedControl *testControl=[[UISegmentedControl alloc]initWithFrame:frame];
    testControl.momentary=YES;
    [testControl insertSegmentWithTitle:@"Delete" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"" atIndex:0 animated:NO];
    [testControl insertSegmentWithTitle:@"Back" atIndex:0 animated:NO];
    testControl.tag=KDetailSceneTestControlTag;
    //添加测试按钮触发的测试方法
    [testControl addTarget:self action:@selector(testSegue:) forControlEvents:UIControlEventValueChanged];
    [_detailScene addSubview:testControl];

return _detailScene;
}

三,每个页面都得跳转,跳转方法添加如下:     (出口方法不确定是否有参数,我们传递一个参数为id类型)

#pragma mark -mainScene         出口方法
-(void)mainSceneToAboutScene:(id)sender
{
    //将关于界面提前
    [self.view bringSubviewToFront:self.aboutScene];
}
-(void)mainSceneToEditScene:(id)sender
{
    //将编辑界面提前
    [self.view bringSubviewToFront:self.editScene];
}
-(void)mainSceneToDetailScene:(id)sender
{
    //将详细界面提前
    [self.view bringSubviewToFront:self.detailScene];
}

#pragma mark -aboutScene        出口方法
-(void)aboutSceneBackMainScene:(id)sender
{
    //返回主界面
    [self.view bringSubviewToFront:self.mainScene];
}

#pragma mark -editScene         出口方法
-(void)editSceneToLineColorScene:(id)sender
{
    //将lineColor界面提前
    [self.view bringSubviewToFront:self.lineColorScene];
}

-(void)editSceneToBgColorScene:(id)sender
{
    //将BgColorScene界面提前
    [self.view bringSubviewToFront:self.bgColorScene];
}

-(void)editSceneToLineWidthScene:(id)sender
{
    //LineWidthScene提前
    [self.view bringSubviewToFront:self.lineWidthScene];
}

-(void)editSceneBackMainScene:(id)sender
{
    //MainScene提前
    [self.view bringSubviewToFront:self.mainScene];
}

#pragma mark -lineColorScene    出口方法
-(void)lineColorSceneBackEditScene:(id)sender
{
    //editScene提前
    [self.view bringSubviewToFront:self.editScene];
}

#pragma mark -bgColorScene      出口方法
-(void)bgColorSceneBackEditScene:(id)sender
{
    //editScene提前
    [self.view bringSubviewToFront:self.editScene];
}

#pragma mark -lineWidthScene    出口方法
-(void)lineWidthSceneBackEditScene:(id)sender
{
    //editScene提前
    [self.view bringSubviewToFront:self.editScene];
}

#pragma mark -detailScene       出口方法
-(void)detailSceneToEditScene:(id)sender
{
    //editScene提前
    [self.view bringSubviewToFront:self.editScene];
}

-(void)detailSceneBackMainScene:(id)sender
{
    //mainScene提前
    [self.view bringSubviewToFront:self.mainScene];
}

四,定义页面的tag作为宏

#define KMainSceneTestControlTag        1001
#define KAboutSceneTestControlTag       1002
#define KEditSceneTestControlTag        1003
#define KLineColorSceneTestControlTag   1004
#define KBgColorSceneTestControlTag     1005
#define KLineWidthSceneTestControlTag   1006
#define KDetailSceneTestControlTag      1007

五,实现跳转,都是一个模式,看一个就知道其他的了,下面把所有的都列举出来,其实并不复杂

#pragma mark --测试程序流程的方法
-(void)testSegue:(UISegmentedControl *)testControl
{
    switch (testControl.tag) {
        case KMainSceneTestControlTag:
        {
            switch (testControl.selectedSegmentIndex) {
                case 0:
                {
                    [self mainSceneToEditScene:nil];
                    break;
                }
                case 1:
                {
                    break;
                }
                case 2:
                {
                    [self mainSceneToAboutScene:nil];
                    break;
                }
                    
                default:
                    break;
            }
             break;
        }
            
        case KAboutSceneTestControlTag:
        {
            switch (testControl.selectedSegmentIndex) {
                case 0:
                {
                    [self aboutSceneBackMainScene:nil];
                    break;
                }
                case 1:
                {
                    
                    break;
                }
                case 2:
                {
                    
                    break;
                }
                    
                default:
                    break;
            }
            break;
        }
        case KEditSceneTestControlTag:
        {
            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;
        }
            
        case KLineColorSceneTestControlTag:
        {
            switch (testControl.selectedSegmentIndex) {
                case 0:
                {
                   [self lineColorSceneBackEditScene:nil];
                    break;
                }
                case 1:
                {
                   
                    break;
                }
                case 2:
                {
                    [self lineColorSceneBackEditScene:nil];
                    break;
                }
                    
                default:
                    break;
            }
            break;
        }
        case KLineWidthSceneTestControlTag:
        {
            switch (testControl.selectedSegmentIndex) {
                case 0:
                {
                    [self lineWidthSceneBackEditScene:nil];

break;
                }
                case 1:
                {
                    
                    break;
                }
                case 2:
                {
                    [self lineWidthSceneBackEditScene:nil];
                    break;
                }
                    
                default:
                    break;
            }
            break;
        }
            
        case KBgColorSceneTestControlTag:
        {
            switch (testControl.selectedSegmentIndex) {
                case 0:
                {
                    [self bgColorSceneBackEditScene:nil];
                    break;
                }
                case 1:
                {
                    
                    break;
                }
                case 2:
                {
                   [self bgColorSceneBackEditScene:nil];
                    break;
                }
                    
                default:
                    break;
            }
            break;
        }
        case KDetailSceneTestControlTag:
        {
            switch (testControl.selectedSegmentIndex) {
                case 0:
                {
                    [self detailSceneToEditScene:nil];
                    break;
                }
                case 1:
                {
                    
                    break;
                }
                case 2:
                {
                    [self detailSceneBackMainScene:nil];
                    break;
                }
                    
                default:
                    break;
            }
            break;
        }           
        default:
            break;
            
    }

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

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

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

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

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

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

    // //  CHViewController.m //  SuperDrawingSample // //  Created by JaikenLI on 13-11-21. //  Copyrig ...

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

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

  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. (转)直接拿来用!最火的iOS开源项目(一)

    1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...

随机推荐

  1. 20145236 《Java程序设计》 第十周学习总结

    20145236 <Java程序设计> 第十周学习总结 Java网络编程 Java网络编程技术 Java语言是在网络环境下诞生的,所以Java语言虽然不能说是对于网络编程的支持最好的语言, ...

  2. 告别node-forever,拥抱PM2

    告别node-forever,拥抱PM2 返回原文英文原文:Goodbye node-forever,hello PM2 devo.ps团队对JavaScript的迷恋已经不是什么秘密了;node.j ...

  3. 使用 HTML5 canvas 绘制精美的图形

    HTML5 是一个新兴标准,它正在以越来越快的速度替代久经考验的 HTML4.HTML5 是一个 W3C “工作草案” — 意味着它仍然处于开发阶段 — 它包含丰富的元素和属性,它们都支持现行的 HT ...

  4. 开源软件架构总结之——Bash(readline做输入交互式,词法语法分析,进程交互)

    第3章 The Bourne-Again Shell Bash的主要组件:输入处理,解析,单词展开(word expansion)和其他命令处理,管道(pipeline)中的命令执行.这些组件构成一个 ...

  5. [转]Java 泛型: 什么是PECS(Producer Extends, Consumer Super)

    以下内容转自: 原文链接: stackoverflow 翻译: ImportNew.com- 刘志军 译文链接: http://www.importnew.com/8966.html -------- ...

  6. [转]玩转Google开源C++单元测试框架Google Test系列

    gtest的官方网站是: http://code.google.com/p/googletest/ 从官方的使用文档里,你几乎可以获得你想要的所有东西 http://code.google.com/p ...

  7. js使用正则表达式

    参考慕课网示例: 使用js对html输入框内容进行校验: 1. 只能输入5-20个字符,必须以“字母”开头 2. 可以带“数字" “_” “.”的字串 <!DOCTYPE html P ...

  8. 读取raw文件的方法。

    Android开发者有些文件比如音频,视频,.html,.mp3等等这些文件不希望编译器编译而保持原始原貌打包进apk文件(这在游戏开发中很常见和普遍,如游戏用到的游戏音乐.图等资源),那么可以使用A ...

  9. PHP IMAP收QQ邮件,SMTP存入另外QQ邮箱

    作用,将qq1收到邮件,用qq2的账号.以qq0的为发件人身份放到qq2的邮箱. 什么样做这样一个功能,一个朋友要求的,她不告诉我为什么,好吧 <?php define('USER','xxx@ ...

  10. Linux下的多线程编程

    1 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的 Unix也支持线程的概念,但是在一个进程(proces ...