昨天晚上做这个郁闷死了,总是这里那里出问题。。。崩溃,主要还是不熟。结果虽然知道步骤,有大概的模型,可是看见那么多代码,我就找不到北了,严重打击我信心。
不过做了两个晚上,比以前熟悉了一些,也算是一点点收获吧!
------------------------------------------------------------------------------------------------
FirstViewController *viewController = [[FirstViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = navController;
navController.navigationBarHidden=YES;
-----------------------------------------------------------------------------------------------
“ navController.navigationBarHidden=YES; “ 这条代码是隐藏导航控制器
-----------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(52,101,53,33);
[btn setTitle:@"按钮" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(didclicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
上面代码是设置一个按钮,用来导航至子页面。
UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, 320, 416)];
bgImageView.image = [UIImage imageNamed:@"bg_01"];
[self.view addSubview:bgImageView];
UIImageView *bgImageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, 320, 416)];
bgImageView1.image = [UIImage imageNamed:@"bg_01_01"];
[self.view addSubview:bgImageView1];
} 这两行代码是放入两个界面,作为程序的背景。
- (void)didclicked:(UIButton *)sender
{
SecondViewController *ViewController = [[SecondViewController alloc]init];
[self.navigationController pushViewController:ViewController animated:NO];
} 这一段代码是按钮转移至下一页面的关键之处!
----------------------------------------------------------------------------------------------
- (void)createBgView
{
UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 44, 320, 418)];
bgImageView.image = [UIImage imageNamed:@"bg"];
[self.view addSubview:bgImageView];
上一段代码创建了一个背景图片
UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 49)];
titleImageView.image = [UIImage imageNamed:@"titleViewshang"];
[self.view addSubview:titleImageView];
上一段代码创建了一个上标题图片
UIImageView *footerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 49, 320, 49)];
footerImageView.image = [UIImage imageNamed:@"titleViewxia"];
[self.view addSubview:footerImageView];
} 上一段代码创建了一个下标题图片
- (void)createButtons
{
UIButton *backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
backBtn.frame=CGRectMake(10, 6, 70, 35);
[backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(didBackClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backBtn];
上一段代码创建了一个返回按钮
UIButton *clearBtn=[UIButton buttonWithType:UIButtonTypeCustom];
clearBtn.frame=CGRectMake(240, 6, 70, 35);
[clearBtn setImage:[UIImage imageNamed:@"clear"] forState:UIControlStateNormal];
[clearBtn addTarget:self action:@selector(didcleared:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:clearBtn];
上一段代码创建了一个清除按钮
UIButton *voicebtn = [UIButton buttonWithType:UIButtonTypeCustom];
voicebtn.frame=CGRectMake(10, self.view.frame.size.height-52, 67, 52);
[voicebtn setImage:[UIImage imageNamed:@"play1"] forState:UIControlStateHighlighted];
[voicebtn setImage:[UIImage imageNamed:@"play2"] forState:UIControlStateNormal];
[voicebtn addTarget:self action:@selector(didPlayClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:voicebtn];
上一段代码创建了一个声音按钮
UIButton *strokeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
strokeBtn.frame=CGRectMake(130, self.view.frame.size.height-52, 67, 52);
[strokeBtn setImage:[UIImage imageNamed:@"stroke1"] forState:UIControlStateHighlighted];
[strokeBtn setImage:[UIImage imageNamed:@"stroke2"] forState:UIControlStateNormal];
[strokeBtn addTarget:self action:@selector(didstroked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:strokeBtn];
上一段代码创建了一个动画按钮
UIButton *practiceBtn = [UIButton buttonWithType:UIButtonTypeCustom];
practiceBtn.frame=CGRectMake(240, self.view.frame.size.height-52, 67, 52);
[practiceBtn setImage:[UIImage imageNamed:@"practice1"] forState:UIControlStateHighlighted];
[practiceBtn setImage:[UIImage imageNamed:@"practice2"] forState:UIControlStateNormal];
[practiceBtn addTarget:self action:@selector(didpracticed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:practiceBtn];
}上一段代码创建了一个练习按钮
- (void)createAnimation
{
aniImageView=[[UIImageView alloc]initWithFrame:CGRectMake(50, 90, 225, 225)];
NSMutableArray *array = [[NSMutableArray alloc] init];
for(int i=1;i<=10;i++)
{
NSString *name = [NSString stringWithFormat:@"WA~%04d",i];
NSLog(@"%@", name);
UIImage *image=[UIImage imageNamed:name];
[array addObject:image];
}
aniImageView.animationImages = array;
}
- (void)didBackClicked:(UIButton *)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
-(void)didcleared:(UIButton *)sender
{
[aniImageView removeFromSuperview];
[aniImageView stopAnimating];
}
-(void)didstroked:(UIButton *)sender
{
[self createAnimation];
[self.view addSubview:aniImageView];
aniImageView.image = [UIImage imageNamed:@"WA~0010"];
aniImageView.animationDuration = 2;
aniImageView.animationRepeatCount = 1;
[aniImageView startAnimating];
}
-(void)didpracticed:(UIButton *)sender
{
aniImageView.image = [UIImage imageNamed:@"WA~0001"];
[self.view addSubview:aniImageView];
}
- (void)didPlayClicked:(UIButton *)sender
{
AudioServicesPlaySystemSound(soundID);
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self createBgView];
[self createButtons];
[self createAnimation];
NSURL *url = [[NSBundle mainBundle] URLForResource:@"000_a" withExtension:@"mp3"];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(url), &soundID);
} 上代码使用了封装,这是非常实用的一项技巧。