我有一个和这个非常相似的问题:
我只是想用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];
}有人知道哪里出了问题吗?
谢谢,文森特。
发布于 2010-08-21 07:35:40
在为视图的背景层设置动画时,您需要位于UIView动画块内,而不仅仅是CATransaction
[UIView beginAnimations:nil context:NULL];
// ... your animation code
[UIView commitAnimations];发布于 2010-08-25 03:28:06
或者,您可以使用CAAnimationGroup对缩放和旋转动画进行分组,如下所示。
CAAnimationGroup *aniGroup = [CAAnimationGroup animation];
// setup aniGroup properties
CABasicAnimation *scaleAnimation = [CABasicAnimation defaultValueForKey:@"transform.scale"];
scaleAnimation.fromValue = [NSNumber numberWithFloat:0.0];
scaleAnimation.toValue = [NSNumber numberWithFloat:1.0];
// setup scaleAnimation properties
CABasicAnimation *rotateAnimation = [CABasicAnimation defaultValueForKey:@"transform.rotate"];
// setup rotateAnimation properties
// ....
aniGroup.animations = [NSArray arrayWithObjects:rotateAnimation, scaleAnimation, nil];
[self.layer layoutIfNeeded];
[self.layer addAnimation:aniGroup forKey:@"myAnimation"];诸如此类的事情...可能不完全是复制、粘贴和可生成的。;)
希望这能有所帮助!
https://stackoverflow.com/questions/3535543
复制相似问题