UIView动画实现登录页面的UI控件逐渐向上移动并显示

这段代码展示了如何在iOS中实现一系列UI控件的动画效果,通过修改alpha值和frame来创建平移动画。同时,当输入框动画完成后,根据输入状态切换响应的文本字段焦点。这涉及到视图控制器的响应式编程技巧。
- (void)showAnimation {
    //用来存储所有UI控件的alpha值
    _objectsAlpha = [NSMutableArray array];
    // animationObjects 是做动画的的所有UI控件
    for (UIView *animationObject in self.animationObjects) {        
        [_objectsAlpha addObject:@(animationObject.alpha)];
        CGRect animationObjectRect = animationObject.frame;
        animationObjectRect.origin.y += 40;
        animationObject.alpha = 0;
        animationObject.frame = animationObjectRect;
    }
    [self showAnimation:self.animationObjects[0] nextAnimationObject:self.animationObjects[1]];
}

- (void)showAnimation:(UIView *)object nextAnimationObject:(UIView *)nextAnimationObject {
    [UIView animateWithDuration:0.55 delay:0 usingSpringWithDamping:0.7 initialSpringVelocity:0.7 options:UIViewAnimationOptionCurveEaseOut animations:^{        
        NSInteger index = [_animationObjects indexOfObject:object];
        CGFloat alpha = [_objectsAlpha[index] floatValue];
        CGRect animationObjectRect = object.frame;
        animationObjectRect.origin.y -= 40;
        object.alpha = alpha;
        object.frame = animationObjectRect;
    } completion:^(BOOL finished) {
        if (object == self.inputUMPasswordTextField) {
            if (self.inputUMNameTextField.text.length) {                
                [self.inputUMPasswordTextField becomeFirstResponder];
            }else {                
                [self.inputUMNameTextField becomeFirstResponder];
            }
        }
    }];
    
    if (!nextAnimationObject) return;
    
    UIView *nextObject = nil;
    NSInteger nextIndex = [self.animationObjects indexOfObject:nextAnimationObject] + 1;
    if (nextIndex < self.animationObjects.count) {
        nextObject = self.animationObjects[nextIndex];
    }
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self showAnimation:nextAnimationObject nextAnimationObject:nextObject];
    });
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值