iOS 移动动画简单实现

2015-07-08 0 368
[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中只需要直接赋值即可实现效果。

iOS 移动动画简单实现

若使用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>

遇见资源网 objective-c iOS 移动动画简单实现 http://www.ox520.com/17979.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务