清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
[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>