1
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"];
4

3 回答 3

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"];
于 2013-05-27T06:45:52.673 回答
0

有很多关于如何为 UIView 设置动画的教程:如何使用 UIView 动画教程 ,这里也是一个可能有帮助的示例

//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];
于 2013-05-27T06:14:15.557 回答
0

当前,您要求动画在逻辑上应该是 @"frame" 属性时处理 @"key" 属性。但是,无论如何,这对图层不起作用。动画必须知道将指定的更改应用于什么,但它还需要能够将更改应用于“真实”属性。“框架”是派生属性。

要更改您需要为“位置”设置动画的位置并更改您需要为“边界”属性设置动画的大小。

请参阅此 Apple 技术说明:http: //developer.apple.com/library/mac/qa/qa1620/_index.html

于 2013-05-27T06:23:42.077 回答