iOS 移动动画简单实现
2018-07-20 来源:open-open
[UIView animateWithDuration:0.5 animations:^{
for (i = num; i > _indexOfArray+1; i--) {
((UIDragButton *)[_buttonArray objectAtIndex:i]).frame = ((UIDragButton *)[_buttonArray objectAtIndex:i-1]).frame;
}
((UIDragButton *)[_buttonArray objectAtIndex:i]).frame = _frameRect;
}];
在block中只需要直接赋值即可实现效果。
若使用CABasicAnimation则较为复杂
定义动画
- (CABasicAnimation *)moveX:(float)time X:(NSNumber *)x // 横向移动
{
CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
animation.toValue=x;
animation.duration=time; // 动画持续时间
animation.removedOnCompletion=NO;
animation.fillMode=kCAFillModeForwards;
animation.delegate = self;
return animation;
}
使用动画
[self.layer addAnimation:[self moveX:0.1 X:[NSNumber numberWithFloat:x]] forKey:nil];
委托需要协议<NSObject>
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:iOS翻牌效果
下一篇:ios中做出颜色渐变的效果
最新资讯
热门推荐