51音图 一个按键

来源:互联网 发布:棋牌源码论坛eenot 编辑:程序博客网 时间:2024/05/29 17:01

#import "SecondViewController.h"

#import <AudioToolbox/AudioToolbox.h>

@interface SecondViewController ()

{

   UIImageView *aniImageView;

   SystemSoundID soundID;

}


@end


@implementation SecondViewController


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

{

   self = [superinitWithNibName:nibNameOrNil bundle:nibBundleOrNil];

   if (self) {

        // Custom initialization

    }

    return self;

}



- (void)viewDidLoad

{

    [superviewDidLoad];

    //创建顶上的图片

   UIImage *image3 = [UIImageimageNamed:@"titleView.png"];

   UIImageView *imageView3 = [[UIImageViewalloc]init];

    imageView3.image = image3;

    imageView3.frame =CGRectMake(0 ,0, 320,50 );

    [self.viewaddSubview:imageView3];

    //创建界面1

    UIImage *image1 = [UIImageimageNamed:@"kanaDetailBgImg.png"];

   UIImageView *imageView1 = [[UIImageViewalloc]init];

    imageView1.image = image1;

    imageView1.frame =CGRectMake(0 ,48, 320, 380);

    [self.viewaddSubview:imageView1];

    //创建界面2

   UIImage *image4 = [UIImageimageNamed:@"bottomBg.png"];

   UIImageView *imageView4 = [[UIImageViewalloc]init];

    imageView4.image = image4;

    imageView4.frame =CGRectMake(0 ,430 ,320,50 );

    [self.viewaddSubview:imageView4];

    

    //将按钮类添加进来

    [selfcreateButtons];

    //添加一个动画类

   [selfcreateAnimation];

    

    


}

//制作一个动画图片类

-(void)createAnimation

{

    aniImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(55,76,225,225)];

    NSMutableArray *array = [[NSMutableArrayalloc] init];

   for (int i =1; i <= 10 ; i++){

       NSString *name = [NSStringstringWithFormat:@"WA~%04d",i];

       NSLog(@"%@", name);

       UIImage *image = [UIImageimageNamed:name];

        

        [arrayaddObject:image];

       aniImageView.image = [UIImageimageNamed:@"WA~0001.png"];

       aniImageView.animationImages = array;

        [self.viewaddSubview:aniImageView];

    }


}


//创建按钮类将按钮封装起来

-(void)createButtons

{

    UIButton *backbtn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [backbtn setImage:[UIImageimageNamed:@"backBtn.png"]forState:UIControlStateNormal];

    backbtn.frame =CGRectMake(20,8, 70, 35);

    [backbtn addTarget:selfaction:@selector(didBackClicked:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:backbtn];

    

   

    UIButton *PlBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [PlBtn setImage: [UIImageimageNamed:@"strokeOrderBtn_01"]forState:UIControlStateNormal];

    [PlBtn setImage: [UIImageimageNamed:@"strokeOrderBtn_02"]forState:UIControlStateHighlighted];

    PlBtn.frame =CGRectMake(130,self.view.frame.size.height -52, 67, 52);

    [PlBtn addTarget:selfaction:@selector(didplBtnClicked:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:PlBtn];

    

    

    UIButton *voiceBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    voiceBtn.frame =CGRectMake(10,self.view.frame.size.height - 52 , 67, 52);

    [voiceBtn setImage:[UIImageimageNamed:@"pronounceBtn_01"]forState:UIControlStateNormal];

    [voiceBtn setImage:[UIImageimageNamed:@"pronounceBtn_02"]forState:UIControlStateHighlighted];

    [voiceBtn addTarget:selfaction:@selector(didPlayClicked:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:voiceBtn];

    

    

    UIButton *clearBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];

    clearBtn.frame =CGRectMake(240,8, 70, 35);

    [clearBtn setImage:[UIImageimageNamed:@"clearBtn.png"]forState:UIControlStateNormal];

    [clearBtn addTarget:selfaction:@selector(didClearClicked:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:clearBtn];

    


    UIButton *praBtn = [UIButtonbuttonWithType:UIButtonTypeSystem];

    praBtn.frame =CGRectMake(240,self.view.frame.size.height - 52 , 67, 52);

    [praBtn setImage:[UIImageimageNamed:@"practiceBtn_02.png"]forState:UIControlStateNormal];

    [praBtn addTarget:selfaction:@selector(didPraBtn:)forControlEvents:UIControlEventTouchUpInside];

    [self.viewaddSubview:praBtn];  

}


- (void)didplBtnClicked:(UIButton *)sender

{

    NSLog(@"%s",__PRETTY_FUNCTION__);

    aniImageView.animationDuration =2;

    aniImageView.animationRepeatCount =1;

    aniImageView.image = [UIImageimageNamed:@"WA~0010.png"];

    [self.viewaddSubview:aniImageView];

    [aniImageViewstartAnimating];

}


-(void)didPraBtn:(UIButton *)sender

{

 NSLog(@"%s"__PRETTY_FUNCTION__);

}



-(void)didClearClicked:(UIButton *)sender

{

    [aniImageViewremoveFromSuperview];

}


- (void)didBackClicked:(UIButton *)sender

{

    [self.navigationControllerpopViewControllerAnimated:YES];

}


- (void)didPlayClicked:(UIButton *)sender

    {

       NSLog(@"%s",__PRETTY_FUNCTION__);

//播放声音动作

    NSURL *url = [[NSBundle mainBundleURLForResource:@"250_mya"withExtension:@"mp3"];

    AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID);


        AudioServicesPlaySystemSound(soundID);  

    }


- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}




0 0
原创粉丝点击