引言
因为工作中产品给的一个需求,美曰其名:
- 好看,增加用户体验
- 磨砺技术
-
提高程序猿的成就感
就是恶心人,还有视频、抄的。
为了在妹子面前风光就开做吧。
首先分析
- 这个需要自定义一个
view
- 包含:
TextField
、Label
- 动画的方向需要靠左边,并且向上移动、缩小同时进行
操作
- 创建一个自定义
UIView
控件
@interface ZacharyTextField()<UITextFieldDelegate>
{
BOOL IsEditlock;
BOOL IsEditBackLock;
}
/**活动的TextField的控件*/
@property(nonatomic,strong)UITextField *ZsTextField;
/**目前做的是将字符串直接生成图片进行的动画效果*/
@property(nonatomic,strong)UIImageView *ZsImageView;
@property(nonatomic,strong)UILabel *ZsdefaultsLable;
@end
- 使用
initWithCoder
、initWithFrame
这两个方法进行创建,这样可以在xib、代码都可以使用 - 当
TextField
开始编辑的时候调用开始动画
- (void)TextUpAnimation{
if(IsEditlock){
return;
}
IsEditlock = YES;
IsEditBackLock = NO;
self.ZsImageView.center = CGPointMake(0, self.frame.size.height - MyViewScreenHeight);
self.ZsImageView.layer.anchorPoint = CGPointMake(0, 0);//缩小的中心点
//移动动画
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];///.y的话就向下移动。
animation.toValue = [NSNumber numberWithFloat:-(self.frame.size.height - MyViewScreenHeight)];
//缩小动画
CABasicAnimation *ZoomAnima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
ZoomAnima.fromValue = [NSNumber numberWithFloat:1];
ZoomAnima.toValue = [NSNumber numberWithFloat:0.8];
CAAnimationGroup *AnimationGroup = [CAAnimationGroup animation];
AnimationGroup.animations = @[animation,ZoomAnima];
AnimationGroup.duration = 0.3;
AnimationGroup.removedOnCompletion = NO;
AnimationGroup.fillMode = kCAFillModeForwards;
[self.ZsImageView.layer addAnimation:AnimationGroup forKey:@"groupAnimation"];
}
- 当
TextField
结束编辑的时候,判断TextField
是否有值?不回退:回退
- (void)StopEditingAnimaiton{
if(IsEditBackLock) return;
IsEditBackLock = YES;
IsEditlock = NO;
self.ZsImageView.center = CGPointMake(0, 0);
self.ZsImageView.layer.anchorPoint = CGPointMake(0, 0);//缩小的中心点
//移动动画
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];///.y的话就向下移动。
animation.toValue = [NSNumber numberWithFloat:self.frame.size.height - MyViewScreenHeight];
//缩小动画
CABasicAnimation *ZoomAnima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
ZoomAnima.fromValue = [NSNumber numberWithFloat:0.8];
ZoomAnima.toValue = [NSNumber numberWithFloat:1];
CAAnimationGroup *AnimationGroup = [CAAnimationGroup animation];
AnimationGroup.animations = @[animation,ZoomAnima];
AnimationGroup.duration = 0.3;
AnimationGroup.removedOnCompletion = NO;
AnimationGroup.fillMode = kCAFillModeForwards;
[self.ZsImageView.layer addAnimation:AnimationGroup forKey:@"groupAnimation"];
}