美好的一天,每個人!無法設置動畫時長
嗯,我有一個非常簡單的麻煩。 我有一個帶有兩個子層的CATransformLayer,每個子層都帶有「false」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 ;
}
你打電話從哪裏轉來轉去? – Liron
從以下例程: - (無效)的touchesBegan:(NSSet中*)觸摸withEvent:方法(的UIEvent *)事件 { [自旋轉]; } –
另外,如果你在調用'setAnimationCurve'之前調用'setAnimationDuration'? – Liron