UIImageView
1.创建一个UIImageView 2.将图片生成UIImage对象放在数组里 3.拼接图片名(保证图片名一样) 3.生成图片
3.播放一次动画需要的时间 4.指定播放的内容 5.指定播放的次数 6.开始动画(第二页加动画需要注意)
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 200, 150, 150)];
[self.view addSubview:imageView];
[imageView release];
// 把图片生成UIImage对象放在数组里
for (NSInteger i = 0; i < 22; i++) {
// 拼接图片名, 保证图片名一样
NSString *name = [NSString stringWithFormat:@"Zombie%ld.tiff", i];
// NSLog(@"%@", name);
// 生成图片
UIImage *image = [UIImage imageNamed:name];
[self.picArr addObject:image];
}
// 播放一次动画需要的时间
imageView.animationDuration = 1.5;
// 指定播放的内容
imageView.animationImages = self.picArr;
// 指定播放的次数
imageView.animationRepeatCount = NSIntegerMax;
// 开始动画
[imageView startAnimating];
2.textField的协议(7条)<UITextFieldDelegate>
(1)点击return回收键盘(BOOL)shouldReturn
<span style="font-size:18px;">- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}</span>
(2)监控当前的状态(可以实现文本框向上移动)(BOOL)shouldBeginEditing (BOOL)shouldEndEditing
代码实现:先计算textField的中心点的纵坐标和view的纵坐标的中心点的差
如果大于0,view的中心点坐标的纵坐标减去差值
<span style="font-size:18px;">- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
NSLog(@"编辑开始");
CGFloat height = textField.center.y - HEIGHT / 2;
if (height > 0) {
self.view.center = CGPointMake(self.view.center.x, HEIGHT / 2 - height);
}
return YES;
}</span>
结束编辑的时候,回到原来的位置,相对位置是不变的
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
CGFloat heigth = textField.center.y - HEIGHT / 2;
if (heigth > 0) {
self.view.center = CGPointMake(self.view.center.x, self.view.center.y + heigth);
}
return YES;
}
textField的协议方法,用于撤销(可以记录撤销的内容)
- (BOOL)textFieldShouldClear:(UITextField *)textField{
NSLog(@"test");
NSLog(@"%@", textField.text);
return YES;
}
监听当前的输入状态(BOOL)shouldChange
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSLog(@"%@", string);
NSLog(@" %@", textField.text);
if (textField.text.length == 5) {
NSLog(@"yes");
} else{
NSLog(@"no");
}
return YES;
}
确认密码的功能(监听输入状态里实现)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *newText = [NSString stringWithFormat:@"%@%@", textField.text, string];
if ([newText isEqualToString:self.codeView.textField.text]) {
self.imageView.image = [UIImage imageNamed:@"checked.png"];
} else {
self.imageView.image = [UIImage imageNamed:@"check.png"];
}
return YES;
}