UIImageView动画

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;
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值