iOS

核心动画与UIView自带动画选择

2015-11-12  本文已影响186人  iOS_成才录
    CABasicAnimation *anim = [CABasicAnimation animation];
    
    anim.keyPath = @"position";
    
    anim.toValue = [NSValue valueWithCGPoint:CGPointMake(250, 500)];
    
    // 必须设置代理
    anim.delegate = self;
    
    // 取消反弹
    anim.removedOnCompletion = NO;
    anim.fillMode = kCAFillModeForwards;
    
    [_redView.layer addAnimation:anim forKey:nil];

// 当动画完成的时候调用
- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    // 注意:核心动画一切都是假象,并不会真实修改layer的属性
    NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));
}

使用UIView动画

[UIView animateWithDuration:0.25 animations:^{
       
        _redView.layer.position = CGPointMake(250, 500);
        
    } completion:^(BOOL finished) {
        NSLog(@"%@", NSStringFromCGPoint(_redView.layer.position));

    }];
上一篇 下一篇

猜你喜欢

热点阅读