首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CATransaction (静止)未设置动画

CATransaction (静止)未设置动画
EN

Stack Overflow用户
提问于 2010-08-21 07:31:24
回答 2查看 2.7K关注 0票数 1

我有一个和这个非常相似的问题:

CATransaction Not Animating

我只是想用CATransaction来制作一个视图层的动画。我的问题是,转换是立即应用于视图的。

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

下面是我的代码:

代码语言:javascript
复制
- (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];
}

有人知道哪里出了问题吗?

谢谢,文森特。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-08-21 07:35:40

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

代码语言:javascript
复制
[UIView beginAnimations:nil context:NULL];
// ... your animation code
[UIView commitAnimations];
票数 6
EN

Stack Overflow用户

发布于 2010-08-25 03:28:06

或者,您可以使用CAAnimationGroup对缩放和旋转动画进行分组,如下所示。

代码语言:javascript
复制
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"];

诸如此类的事情...可能不完全是复制、粘贴和可生成的。;)

希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3535543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档