CATransaction不动画 [英] CATransaction Not Animating

查看:98
本文介绍了CATransaction不动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在XCode中创建了一个新的基于视图的应用程序。

I've created a new View-based Application in XCode.

在ViewController中,我修改的唯一代码如下:

In the ViewController, the only code that I've modified looks like this:

- (void)viewDidLoad {
[super viewDidLoad];

UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
newView.backgroundColor = [UIColor redColor];
[self.view addSubview:newView];


[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat:0.5f] forKey:kCATransactionAnimationDuration];

newView.layer.frame = CGRectMake(20,20,220,220);

[CATransaction commit];
}

它应该创建一个红色的正方形动画半秒应用程序加载。问题是,它不动画。我不知道为什么。我创建了这个简单的项目来隔离所有的变量,但它仍然不工作。

It should create a red square that animates for half a second as soon as the application loads. The problem is that it does not animate. I can't figure out why. I created this simple project to isolate all variables, and yet it still doesn't work.

任何人都可以帮助或指向一些核心动画的正确方向阅读材料。

Can anyone help out or point me in the right direction of some Core-Animation reading material. I've already gone through all of Apple's stuff.

推荐答案

如果您在CALayer上设置属性,您的代码将按预期动画(它们默认为动画)。对于UIViews动画,你必须在一个块内改变它们的属性如下:

Your code would animate as expected if you were setting properties on a CALayer (they animate by default). For UIViews to animate, you must change their properties within a block like the following:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];

// Change properties here

[UIView commitAnimations];

CATransactions用于将动画分组以便协调,或手动禁用一组对象的动画。

CATransactions are used to group animations so that they are coordinated, or manually disable animations for a group of objects.

这篇关于CATransaction不动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆