maz*_*iak 2 iphone cocoa-touch core-animation objective-c
我在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的所有工作.
如果您在CALayer上设置属性(默认设置为动画),您的代码将按预期动画.要使UIViews动画化,您必须在块中更改其属性,如下所示:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
// Change properties here
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
CATransactions用于对动画进行分组以便协调它们,或者手动禁用一组对象的动画.
归档时间: |
|
查看次数: |
4416 次 |
最近记录: |