CATransaction(仍然)不动画

vda*_*bry 1 iphone core-animation

我有一个与此非常相似的问题:

CATransaction不动画

我只是想尝试使用CATransaction为视图层设置动画.我的问题是变换立即应用于视图.

我尝试使用performSelector执行动画:withObject:afterDelay:没有成功.

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];

 view = [[[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)] autorelease];
 view.backgroundColor = [UIColor blackColor];
 [self.view addSubview:view];

 [self performSelector:@selector(animateView) withObject:nil afterDelay:0.1];
}

-(void) animateView {
 [CATransaction begin];
 [CATransaction setValue:[NSNumber numberWithFloat:3.0f] forKey:kCATransactionAnimationDuration];
    CALayer *layer = view.layer;
    layer.position = CGPointMake(20, 
         300);
    CATransform3D transform = CATransform3DMakeScale(2.0f, 2.0f, 1.0f);
    transform = CATransform3DRotate(transform, acos(-1.0f)*1.5f, 1.5f, 1.5f, 1.5f);
    layer.transform = transform;
    [CATransaction commit];
}
Run Code Online (Sandbox Code Playgroud)

有谁知道出了什么问题?

谢谢,文森特.

Jas*_*man 6

在为视图的背景层设置动画时,您需要位于UIView动画块内,而不仅仅是CATransaction:

[UIView beginAnimations:nil context:NULL];
// ... your animation code
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)