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 に答える