- //Objective-C
- 全局变量 CABasicAnimation * animation;
- _animation = [CABasicAnimation animationWithKeyPath:@"transform"];
- _animation.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
- _animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI/2, 0, 0, 1)];
- _animation.cumulative = YES;
- _animation.duration = 0.2;
- _animation.repeatCount = HUGE_VALF;
- _animation.removedOnCompletion = NO;
- _animation.fillMode = kCAFillModeForwards;
- //开始旋转
- [self.rotateImageView.layer addAnimation:_animation forKey:@"transform"];
- //停止旋转
- [self.rotateImageView.layer removeAnimationForKey:@"transform"];
- //Swift
- //旋转
- self.rotateTimer = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: #selector(ViewController.rotated), userInfo: nil, repeats: true)
- self.rotateImageView.transform = CGAffineTransformRotate(self.rotateImageView.transform, CGFloat(20.0/180*M_PI))
- //放大缩小动画
UIView.animateWithDuration(0.05, animations: {
//放大
self.rotateImageView.frame = CGRect(x: self.orgFrame.origin.x - 10, y: self.orgFrame.origin.y - 10, width: self.orgFrame.size.width + 20, height: self.orgFrame.size.height + 20)
}) { (_) in
//缩小
self.rotateImageView.frame = CGRect(x: self.orgFrame.origin.x - 5, y: self.orgFrame.origin.y - 5, width: self.orgFrame.size.width + 10, height: self.orgFrame.size.height + 10)
} - //直接旋转一定的角度(_bakImageView是UIImageView类型对象)
- _bakImageView.transform = CGAffineTransformMakeRotation(-M_PI_2);
- -M_PI_2 从逆时针旋转90度
转载于:https://my.oschina.net/pingAds/blog/727209