我有一个自定义UIView类,我想同时旋转,缩小并以随机角度离开屏幕。
我有这个代码会将图层旋转几次
- (void)spinLayer:(CALayer *)inLayer duration:(CFTimeInterval)inDuration currentAngle:(CGFloat)curAngle
direction:(int)direction
{
CABasicAnimation* rotationAnimation;
// Rotate about the z axis
rotationAnimation =
[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
// Rotate 360 degress, in direction specified
rotationAnimation.toValue = [NSNumber numberWithFloat:(M_PI * 4 * direction) + curAngle];
// Perform the rotation over this many seconds
rotationAnimation.duration = inDuration;
// Set the pacing of the animation
rotationAnimation.timingFunction =
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
// Add animation to the layer and make it so
[inLayer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
我称之为:
CGFloat angle = atan2(sender.transform.b, sender.transform.a); // Current angle
[self spinLayer:sender.layer duration:0.5 currentAngle:angle direction:1]; //direction can be -1
但是我现在怎么能缩小视图并同时移动它呢?
由于
答案 0 :(得分:1)
将视图旋转360度不产生动画,因为开始和结束状态相同。您应该尝试使用多个值作为旋转值。