the label is not animating . . . .
UILabel * m_pLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 100, 40)];
[m_pLabel setBackgroundColor:[UIColor redColor]];
[self.view addSubview:m_pLabel];
CABasicAnimation * m_pAnimationObj = [CABasicAnimation animationWithKeyPath:@"key"];
[m_pAnimationObj setFromValue:[NSValue valueWithCGRect:CGRectMake(100, 10, 100, 40)]];
[m_pAnimationObj setToValue:[NSValue valueWithCGRect:CGRectMake(100, 500, 100, 40)]];
m_pAnimationObj.duration = 5.0;
m_pAnimationObj.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[m_pLabel.layer addAnimation:m_pAnimationObj forKey:@"key"];
答案 0 :(得分:1)
试试这个..希望这会对你有帮助。
UILabel * m_pLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 100, 40)];
[m_pLabel setBackgroundColor:[UIColor redColor]];
[self.view addSubview:m_pLabel];
CABasicAnimation * m_pAnimationObj = [CABasicAnimation animationWithKeyPath:@"transform.translation"];
[m_pAnimationObj setFromValue:[NSValue valueWithCGRect:CGRectMake(100, 10, 100, 40)]];
[m_pAnimationObj setToValue:[NSValue valueWithCGRect:CGRectMake(100, 500, 100, 40)]];
m_pAnimationObj.duration = 1.0;
m_pAnimationObj.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[m_pLabel.layer addAnimation:m_pAnimationObj forKey:@"animations"];
答案 1 :(得分:0)
有很多关于如何动画UIView的教程:How To Use UIView Animation Tutorial 这里还有一个可能有用的例子
//UIViewAnimationOptionAutoreverse option, try the code below:
UIView * testView = [[UIView alloc] initWithFrame:CGRectMake(20.0f, 100.0f, 300.0f, 200.0f)];
[testView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:testView];
[UIView animateWithDuration:0.3f
delay:0.0f
options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
[testView setFrame:CGRectMake(0.0f, 100.0f, 300.0f, 200.0f)];
}
completion:nil];
[testView release];
答案 2 :(得分:0)
目前,您要求动画处理@“key”属性,因为它在逻辑上应该是@“frame”属性。但是,无论如何,这都不适用于某个层。动画必须知道应用指定更改的内容,但它还需要能够将更改应用于“true”属性。 “frame”是派生属性。
更改“位置”动画所需的位置,并更改“边界”属性动画所需的大小。
请参阅此Apple技术说明:http://developer.apple.com/library/mac/qa/qa1620/_index.html