2

我正在我的应用程序中移动 UILabel,我希望它在几帧内更改位置和大小,而不是跳跃位置。我正在为 Iphone 使用 Objective-c 和可可开发。谁能帮我吗?

4

2 回答 2

9

最简单的方法是:

    CGRect endFrame = /*The frame of your label in end position*/

    [UIView animateWithDuration:0.5 animations:^{ 
        myLabel.frame = endFrame;
   }];
于 2012-07-27T02:34:02.580 回答
3

此代码对您的问题有帮助

#define FONT_SIZE 14
#define DURATION  10
#define DELAY     10
-(void)viewWillAppear:(BOOL)animated {


  NSString* string = @"My Label";

  CGSize framesize = [string sizeWithFont:[UIFont fontWithName:@"Copperplate" size:FONT_SIZE]];

  // Origin
  float x0 = 0;
  float y0 = 0;

  CGRect  appFrame       = [[UIScreen mainScreen] applicationFrame];
  CGFloat appFrameWidth  = appFrame.size.width;
  CGFloat appFrameHeight = appFrame.size.height;

  // Destination
  float x1 = appFrameWidth - framesize.width;
  float y1 = appFrameHeight - framesize.height;

  UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(x0, y0, framesize.width, framesize.height)];
  label.backgroundColor = [UIColor clearColor];
  label.text = string;
  label.shadowColor = [UIColor grayColor];
  label.shadowOffset = CGSizeMake(1,2);
  label.font = [UIFont fontWithName:@"Copperplate" size:FONT_SIZE];

  [self.view addSubview:label];

  [UIView animateWithDuration:DURATION
                        delay:DELAY
                      options:UIViewAnimationOptionAllowUserInteraction
                   animations:^{
                       label.frame = CGRectMake(x1, y1, framesize.width, framesize.height);
                   }
                   completion:^(BOOL finished){
                     [label removeFromSuperview];
                   }];
}
于 2012-07-27T04:57:50.290 回答