我在XCode中创建了一个新的基于视图的应用程序.
在ViewController中,我修改过的唯一代码如下所示:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
它应该创建一个红色方块,一旦应用程序加载就会激活半秒.问题是它没有动画.我无法弄清楚为什么.我创建了这个简单的项目来隔离所有变量,但它仍然不起作用.
任何人都可以帮助或指出我在一些核心动画阅读材料的正确方向.我已经完成了Apple的所有工作.