首页 > 代码库 > 导航控制器

导航控制器

#import "ViewController.h"

#import "SecondController.h"

 

@interface ViewController ()

 

@end

 

@implementation ViewController

 

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];

    UIImage *image0 = [UIImage imageNamed:@"bg_01"];

    image.image = image0;

    [self.view addSubview:image];

    UIImage *image1 = [UIImage imageNamed:@"bg_01_01"];

    UIImageView *imagev = [[UIImageView alloc] initWithImage:image1];

    imagev.frame = CGRectMake(0, 0, 320, 480);

    [image addSubview:imagev];

    

    UIButton *mu = [UIButton buttonWithType:UIButtonTypeSystem];

    mu.frame = CGRectMake(155, 278, 54, 40);

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

    [self.view addSubview:mu];

    

    UIButton *yo = [UIButton buttonWithType:UIButtonTypeSystem];

    yo.frame = CGRectMake(259, 319, 54, 40);

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

    [self.view addSubview:yo];    

    

}

 

- (void)mu{

    SecondController *Ctrl = [[SecondController alloc] init];

    Ctrl.url = [[NSBundle mainBundle] URLForResource:@"062_mu" withExtension:@"mp3"];

    Ctrl.i = 1;

    [self.navigationController pushViewController:Ctrl animated:YES];

}

 

- (void)yo{

    SecondController *Ctrl = [[SecondController alloc] init];

        Ctrl.url = [[NSBundle mainBundle] URLForResource:@"074_yo" withExtension:@"mp3"];

    Ctrl.i = 0;

    [self.navigationController pushViewController:Ctrl animated:YES];

}

 

- (void)didReceiveMemoryWarning

 

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

 

 

 

#import "SecondController.h"#import <AudioToolbox/AudioToolbox.h>@interface SecondController (){    UIImageView *aniImageView;    SystemSoundID soundID;    UILabel *label;}@end@implementation SecondController- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];    if (self) {        // Custom initialization    }    return self;}-(void)creatView{    UIImageView *bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 45, 320, 418)];    bgView.image = [UIImage imageNamed:@"kanaDetailBgImg" ];    [self.view addSubview:bgView ];        UIImageView *titleView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 49)];    titleView.image = [UIImage imageNamed:@"titleView"];    [self.view addSubview:titleView];        UIImageView *bottomView = [[UIImageView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height-49 , 320, 49)];    bottomView.image = [UIImage imageNamed:@"bottomBg"];    [self.view addSubview:bottomView];        label = [[UILabel alloc] initWithFrame:CGRectMake(140, 0, 45, 45)];    label.textColor = [UIColor whiteColor];    label.font = [UIFont fontWithName:@"fangzhengkatongjianti" size:22];    [titleView addSubview:label];    }-(void)creatButton{    //返回键    UIButton *backBn = [UIButton buttonWithType:UIButtonTypeCustom];    [backBn setImage:[UIImage imageNamed:@"backBtn"] forState:UIControlStateNormal];    backBn.frame = CGRectMake(10, 5, 70, 35);    [backBn addTarget:self action:@selector(BackClicked:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:backBn];        //动画键    UIButton *playBn = [UIButton buttonWithType:UIButtonTypeCustom];    [playBn setImage:[UIImage imageNamed:@"strokeOrderBtn_01"] forState:UIControlStateNormal];    //按钮按下去是高亮状态    [playBn setImage:[UIImage imageNamed:@"strokeOrderBtn_02"] forState:UIControlStateHighlighted];    playBn.frame = CGRectMake(130, self.view.frame.size.height-40, 70, 35);    [playBn addTarget:self action:@selector(palyClicked:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:playBn];        //发音键    UIButton *voiceBn = [UIButton buttonWithType:UIButtonTypeCustom];    [voiceBn setImage:[UIImage imageNamed:@"pronounceBtn_01"] forState:UIControlStateNormal];    [voiceBn setImage:[UIImage imageNamed:@"pronounceBtn_02"] forState:UIControlStateHighlighted];    voiceBn.frame = CGRectMake(10, self.view.frame.size.height-40, 70, 35);    [voiceBn addTarget:self action:@selector(voiceClicked:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:voiceBn];        //练习键    UIButton *practiceBn = [UIButton buttonWithType:UIButtonTypeCustom];    [practiceBn setImage:[UIImage imageNamed:@"practiceBtn_01"] forState:UIControlStateNormal];    [practiceBn setImage:[UIImage imageNamed:@"practiceBtn_02"] forState:UIControlStateHighlighted];    practiceBn.frame = CGRectMake(250, self.view.frame.size.height-40, 70, 35);    [practiceBn addTarget:self action:@selector(practiceClicked:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:practiceBn];            }-(void)creatAnimation{        aniImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mu0017"]];        aniImageView.frame = CGRectMake(50, 85, 225, 225);        //NSArray        NSMutableArray *array = [[NSMutableArray alloc] init];        for (int i = 1; i <= 17; i++) {            NSString *name = [NSString stringWithFormat:@"mu%04d", i];             UIImage *image = [UIImage imageNamed:name];            [array addObject:image];        }        aniImageView.animationImages = array;        aniImageView.animationDuration = 2.5;        aniImageView.animationRepeatCount = 1;        [self.view addSubview:aniImageView];}-(void)creatAnimation0{    aniImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yo0012"]];    aniImageView.frame = CGRectMake(50, 85, 225, 225);    //NSArray    NSMutableArray *array = [[NSMutableArray alloc] init];    for (int i = 1; i <= 12; i++) {        NSString *name = [NSString stringWithFormat:@"yo%04d", i];        UIImage *image = [UIImage imageNamed:name];        [array addObject:image];    }    aniImageView.animationImages = array;    aniImageView.animationDuration = 2.5;    aniImageView.animationRepeatCount = 1;    [self.view addSubview:aniImageView];    }-(void)BackClicked:(UIButton *)sender{    NSLog(@"%s", __PRETTY_FUNCTION__);    [self.navigationController popViewControllerAnimated:YES];}-(void)palyClicked:(UIButton *)sender{    label.text = @"笔 顺";    [aniImageView startAnimating];}-(void)voiceClicked:(UIButton *)sender{    label.text = @"发 音";    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(_url), &soundID);    [aniImageView stopAnimating];    AudioServicesPlaySystemSound(soundID);}-(void)practiceClicked:(UIButton *)sender{    label.text = @"练 习";    [aniImageView stopAnimating];}- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    [self creatView];    [self creatButton];        if(self.i== 1){        [self creatAnimation];    }    else if(self.i == 0){         [self creatAnimation0];    }    }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}@end