iOS CABasicAnimation 动画受layer.anchorPoint和layer.position 的影响

<p>设置iOS CABasicAnimation 动画的时候,设置了<span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 13px;">layer</span><span style="font-family: Menlo; font-size: 13px;">.</span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 13px;">anchorPoint 就需要重新再设置 ayer.position </span></p><p><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 13px;">以下是代码</span></p>

#import "SongRecordCell.h"
#import "BoxConnectManager.h"

@implementation SongRecordCell

- (void)awakeFromNib {
    // Initialization code
    
    UIImageView *imagebg = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 70, 30)];
    imagebg.image = [UIImage imageNamed:@"done_list_btn_keeping1"];
    UIImageView *imageTop = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 70, 30)];
    imageTop.image = [UIImage imageNamed:@"done_list_btn_keeping3"];
    imageTop.contentMode = UIViewContentModeLeft;
    imageTop.clipsToBounds = YES;
    imageTop.layer.anchorPoint = CGPointMake(0, 0.5);
    imageTop.layer.position = CGPointMake(15, imageTop.center.y);
    [self.uploadView addSubview:imagebg];
    [self.uploadView addSubview:imageTop];
    self.uploadingImgView = imageTop;
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(15, 15, 70, 30);
    [btn setTitle:@"上传中" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [self.uploadView addSubview:btn];
}

- (void)setIsPlaying:(BOOL)isPlaying{
    if (isPlaying) {
        
        if ([self.uploadingImgView.layer animationForKey:@"Rotation"] == nil) {
            
            CABasicAnimation* rotationAnimation;
            rotationAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size.width"];
            rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
            rotationAnimation.toValue = [NSNumber numberWithFloat:70.0f];
            [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
            rotationAnimation.duration = 1.5;
            rotationAnimation.repeatCount = CGFLOAT_MAX;//你可以设置到最大的整数值
//            rotationAnimation.cumulative = NO;
            rotationAnimation.removedOnCompletion = NO;
//            rotationAnimation.fillMode = kCAFillModeForwards;
            [self.uploadingImgView.layer addAnimation:rotationAnimation forKey:@"Rotation"];
        }
    } else {
        [self.uploadingImgView.layer removeAllAnimations];
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值