簡單的旋轉動畫和貝塞爾半圓動畫
!
簡單的旋轉動畫和貝塞爾半圓動畫(比較基礎和簡單,直接上代碼)
/**
添加旋轉動畫
@param imageView 旋轉的目標圖片
@param duration 旋轉持續時間
@param clockwise 旋轉的方向(正向還是逆向)
*/
- (void)startrRotationImageView:(UIImageView *)imageView duration:(CGFloat)duration clockwise:(BOOL)clockwise {
CABasicAnimation* rotationAnimation;
//動畫的方式,繞着z軸
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
//旋轉的弧度
rotationAnimation.toValue = [NSNumber numberWithFloat: clockwise ? M_PI * 2.0 : -M_PI * 2.0 ];
//動畫持續的時間
rotationAnimation.duration = duration;
//動畫角度值是否累加(默認爲NO)
rotationAnimation.cumulative = NO;
//重複次數
rotationAnimation.repeatCount = 1;
//動畫添加到layer上
[imageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
/**
沿着UIBezierPath運動
@param imageView 目標b圖片
@param duration 動畫持續時間
@param controlPoint 控制點
@param clockwise 旋轉方向(正向還是逆向)
*/
- (void)startrRotationImageView:(UIImageView *)imageView duration:(CGFloat)duration controlPoint:(CGPoint)controlPoint clockwise:(BOOL)clockwise {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
//設置動畫屬性,因爲是沿着貝塞爾曲線動,所以要設置爲position
animation.keyPath = @"position";
//設置動畫時間
animation.duration = duration;
// 告訴在動畫結束的時候不要移除
animation.removedOnCompletion = YES;
// 始終保持最新的效果
//animation.fillMode = kCAFillModeForwards;
//貝塞爾曲線
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:controlPoint radius:((_dotMargin + _dotNomalSize.width ) /2.0) startAngle: clockwise ? M_PI : 0 endAngle: clockwise ? 0 : M_PI clockwise: clockwise];
// 設置貝塞爾曲線路徑
animation.path = circlePath.CGPath;
// 將動畫對象添加到視圖的layer上
[imageView.layer addAnimation:animation forKey:@"position"];
}
寫在最後
以上內容只是DDGBannerScrollView 只是其中一項功能,更多功能可參照DDGBannerScrollView庫
奉上github地址:DDGBannerScrollView
掘金地址:DDGBannerScrollView
簡書地址:DDGBannerScrollView