最近项目需求,有个蓝牙搜索扫描的功能,美工给予了一张静态的搜索视图,而需要的效果是实现模仿雷达转动扫描的效果,下面的两种实现的方案
效果图:
方案一:
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = @0.0f;
rotationAnimation.toValue = @(2 * M_PI);
rotationAnimation.speed = 0.5;
rotationAnimation.duration = 1.0;
rotationAnimation.repeatCount = HUGE_VALF;
_serchTipLable.hidden = NO;
[self.radarImageView.layer addAnimation:rotationAnimation forKey:@"radarAnimation"];
方案二:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI / 2.0 ];
rotationAnimation.duration = .5;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = MAXFLOAT;
[_rotatingImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
});