最近項目需求竣贪,有個藍(lán)牙搜索掃描的功能划滋,美工給予了一張靜態(tài)的搜索視圖,而需要的效果是實現(xiàn)模仿雷達(dá)轉(zhuǎn)動掃描的效果粉怕,下面的兩種實現(xiàn)的方案
效果圖:
搜索圖片
方案一:
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"];
});