<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];
}
}