今天是个好日子!
嗯,我有一个非常简单的麻烦。我有一个带有两个子层的 CATransformLayer,每个子层都有“假”的 doubleSided 属性,这形成了一张双面卡片。问题是,我无法设置动画持续时间或任何其他选项,例如 UIViewAnimationCurveEaseInOut 等。我尝试了新的和旧的一种方法来向我的图层添加动画选项和持续时间,但不幸的是,它旋转了大约 0, 25 秒,作为默认值状态。怎么了?任何建议,将不胜感激。
这是代码:
1)所有东西的初始化:
#ifndef SUPPORTED_MACRO
#define DEGREES_TO_RADIANS(angle) (angle * M_PI / 180.0)
#endif
- (void)viewDidLoad
{
[super viewDidLoad];
[super viewDidLoad];
CATransformLayer *cardContainer = [CATransformLayer layer];
cardContainer.anchorPoint = CGPointMake( 0.5 , 1.0 ) ;
cardContainer.position = CGPointMake(100.0, 200.0) ;
cardContainer.bounds = CGRectMake(0.0, 0.0, 150.0, 170.0);
CALayer *cardFront = [CALayer layer]; // the front part of card
cardFront.bounds = CGRectMake(0.0, 0.0, cardContainer.bounds.size.width, cardContainer.bounds.size.height) ;
cardFront.frame = cardContainer.bounds ;
cardFront.contentsGravity = kCAGravityResizeAspect ;
cardFront.borderColor = [UIColor blackColor].CGColor;
cardFront.borderWidth = 2.0;
cardFront.cornerRadius = 30.0;
[cardContainer addSublayer:cardFront];
CALayer *cardBack = [CALayer layer]; //back part of card
cardBack.bounds = CGRectMake(0.0, 0.0, cardContainer.bounds.size.width, cardContainer.bounds.size.height) ;
cardBack.frame = cardContainer.bounds;
cardBack.contentsGravity = kCAGravityResizeAspect ;
cardBack.borderColor = [UIColor blackColor].CGColor;
cardBack.borderWidth = 2.0;
cardBack.cornerRadius = 30.0;
cardBack.doubleSided = NO;
cardBack.transform = CATransform3DMakeRotation(DEGREES_TO_RADIANS(180.0),0.0,1.0,0.0);
[cardContainer addSublayer:cardBack];
((CALayer*)[cardContainer.sublayers objectAtIndex:0]).contents = (id)[UIImage imageNamed:@"1.png"].CGImage ;
((CALayer*)[cardContainer.sublayers objectAtIndex:1]).contents = (id)[UIImage imageNamed:@"2.png"].CGImage ;
TL = cardContainer ;
[self.view.layer addSublayer:cardContainer];
}
2)旋转程序(以不推荐的方式):
-(void)Rotate
{
static double CallCounter = 1.0 ;
auto CATransform3D t3d = CATransform3DIdentity;
t3d.m34 = 1.0/-500.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.75];
TL.sublayerTransform = CATransform3DRotate(t3d, -(CallCounter*M_PI) , 1.0, 0.0, 0.0) ;
[UIView commitAnimations];
CallCounter += 1.0 ;
}