- (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];
});
}
UIView动画实现登录页面的UI控件逐渐向上移动并显示
最新推荐文章于 2022-02-27 19:35:32 发布
这段代码展示了如何在iOS中实现一系列UI控件的动画效果,通过修改alpha值和frame来创建平移动画。同时,当输入框动画完成后,根据输入状态切换响应的文本字段焦点。这涉及到视图控制器的响应式编程技巧。

281

被折叠的 条评论
为什么被折叠?



