首页 > 代码库 > 导航控制器
导航控制器
#import "ViewController.h"#import "SecondViewController.h"@interface ViewController () @end@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; UIImage *image=[UIImage imageNamed:@"bg_01.png"]; imageview.image=image; [self.view addSubview:imageview]; UIImageView *imagview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)]; UIImage *imag=[UIImage imageNamed:@"bg_01_01.png"]; imagview.image=imag; [self.view addSubview:imagview]; UIButton *backbutton=[UIButton buttonWithType:UIButtonTypeCustom]; backbutton.frame=CGRectMake(70,45,36, 32); [backbutton addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:backbutton]; // Do any additional setup after loading the view, typically from a nib.}-(void)click1:(UIButton *)sender{ NSLog(@"%s", __PRETTY_FUNCTION__); SecondViewController *secondCtrl = [[SecondViewController alloc] init]; secondCtrl.title = @"Second"; secondCtrl.url = [[NSBundle mainBundle] URLForResource: @"000_a" withExtension:@"mp3"]; [self.navigationController pushViewController:secondCtrl animated:YES];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
#import "SecondViewController.h"#import <AudioToolbox/AudioToolbox.h>@interface SecondViewController ()@end@implementation SecondViewController{UIImageView *aniImageView; SystemSoundID soundID;}- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self;}-(void)creatview{ UIImageView *backview=[[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 418)]; backview.image=[UIImage imageNamed:@"kanaDetailBgImg"]; [self.view addSubview:backview]; UIImageView *startview=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 49)]; startview.image=[UIImage imageNamed:@"titleView"]; [self.view addSubview:startview]; UIImageView *endview=[[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-49, 320, 52)]; endview.image=[UIImage imageNamed:@"bottomBg"]; [self.view addSubview:endview]; }-(void)button{ UIButton *backbutton=[UIButton buttonWithType:UIButtonTypeCustom]; [backbutton setImage:[UIImage imageNamed:@"backBtn"] forState:UIControlStateNormal]; backbutton.frame=CGRectMake(10, 6, 70, 35); [backbutton addTarget:self action:@selector(click1:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:backbutton]; //3. 下面的按钮 UIButton *voiceBtn = [UIButton buttonWithType:UIButtonTypeCustom]; voiceBtn.frame = CGRectMake(10, self.view.frame.size.height - 52, 67, 52); [voiceBtn setImage:[UIImage imageNamed:@"pronounceBtn_01"] forState:UIControlStateNormal]; //按钮按下去是高亮状态 [voiceBtn setImage:[UIImage imageNamed:@"pronounceBtn_02"] forState:UIControlStateHighlighted]; [voiceBtn addTarget:self action:@selector(Play:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:voiceBtn]; }-(void)button1{ // NSLog(@"%s", __PRETTY_FUNCTION__); // UIButton *bakbutton=[UIButton buttonWithType:UIButtonTypeCustom]; bakbutton.frame=CGRectMake(100, 6, 70, 35); [bakbutton setImage:[UIImage imageNamed:@"practiceBtn"] forState:UIControlStateNormal]; [bakbutton addTarget:self action:@selector(animation) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:bakbutton]; }-(void)animation{ int i=1; aniImageView=[[UIImageView alloc]initWithFrame:CGRectMake(45, 75, 255, 255)]; NSMutableArray *array=[[NSMutableArray alloc] init]; for (i=1; i<=11; i++) { NSString *name=[NSString stringWithFormat:@"wo%04d", i]; NSLog(@"%@", name); UIImage *image = [UIImage imageNamed:name]; [array addObject:image]; } aniImageView.animationImages = array; [self.view addSubview:aniImageView]; aniImageView.animationDuration=5; aniImageView.animationRepeatCount = 1; aniImageView.animationImages = array; //跳动的图片 [aniImageView startAnimating]; //调用方法 [self.view addSubview:aniImageView];}- (void)click1:(UIButton *)sender{ SecondViewController *secondcontor=[[SecondViewController alloc]init]; secondcontor.view.backgroundColor =[UIColor greenColor]; [self.navigationController pushViewController:secondcontor animated:YES]; NSLog(@"%s", __PRETTY_FUNCTION__);}- (void)Play:(UIButton *)sender{ NSLog(@"aaaaa%s", __PRETTY_FUNCTION__); AudioServicesCreateSystemSoundID((__bridge CFURLRef)(_url), &soundID); AudioServicesPlaySystemSound(soundID);}- (void)viewDidLoad { [super viewDidLoad]; [self creatview]; [self button]; [self button1]; UIImageView *imageview=[[UIImageView alloc]initWithFrame:CGRectMake(45, 75, 255, 255)]; UIImage *image=[UIImage imageNamed:@"u0011.png"]; imageview.image=image; [self.view addSubview:imageview]; self.navigationController.navigationBarHidden=YES; NSURL *url = [[NSBundle mainBundle] URLForResource:@"000_a" withExtension:@"mp3"]; AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID); //NSURL *url = [NSBundle mainBundle] URLForResource:@"124-do" withExtension:@"mp3" // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/@end
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。