iphone - 如何在UILabel iPhone sdk中提供跑马灯效果?

标签 iphone ios uikit uilabel

<分区>

我想向 UILabel 添加自动滚动效果。

我尝试在互联网上查找任何代码,但没有成功。

一些代码可以在 http://blog.stormyprods.com/2009/10/simple-scrolling-uilabel-for-iphone.html 找到.讨论的解决方案通过 IBOutlet 添加 UIScrollview 来实现自动滚动。

** 我已经编辑了问题,以便给定的部分更好地理解 - 但问题仍然不清楚,恐怕 **(直到)

最佳答案

我不太确定,但我认为你必须按帧制作动画。当你设置标签的坐标时,放置像 x,y 这样的变量而不是参数 1 和 2 的值。 并将其放入动画计时器中,并更改 x 和 y 的值。

类似的代码,它用于图像,您也可以对标签执行此操作:-

// Build array of images, cycling through image names
  for (int i = 0; i < IMAGE_COUNT; i++)
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"Frame_%d.jpg", i]]];

  // Animated images - centered on screen
  animatedImages = [[UIImageView alloc] 
     initWithFrame:CGRectMake(
        (SCREEN_WIDTH / 2) - (IMAGE_WIDTH / 2), 
        (SCREEN_HEIGHT / 2) - (IMAGE_HEIGHT / 2) + STATUS_BAR_HEIGHT,
        IMAGE_WIDTH, IMAGE_HEIGHT)];
  animatedImages.animationImages = [NSArray arrayWithArray:imageArray];

  // One cycle through all the images takes 1.5 seconds
  animatedImages.animationDuration = 1.0;

  // Repeat forever
  animatedImages.animationRepeatCount = -1;

  // Add subview and make window visible
  [window addSubview:animatedImages];
  [window makeKeyAndVisible];

  // Start it up
  animatedImages.startAnimating;

  // Wait 5 seconds, then stop animation
    [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:1000];

希望对你有帮助..:)

关于iphone - 如何在UILabel iPhone sdk中提供跑马灯效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8182579/

上一篇:iphone - 从 iPhone 向 Ruby on Rails (RoR) 服务器发送多部分请求

下一篇:ios - 为什么regionWillChangeAnimated是: never called while panning?

相关文章:

iphone - [UIDeviceRGBColor set] : message sent to deallocated instance

iPhone 通话记录/历史记录

ios - 我的 UI 搜索栏无法工作/向其他网站发送请求

ios - 执行 UIKit 动画 block ,例如 animateWithDuration :animations:completion use CADisplaylink?

ios - iOS 中的 Swift : Resizing UIImage for Portrait or Landscape

ios - 使用 iPhone 模拟器在 openGL ES 上测试手势

objective-c - 如何在 Objective-C 中正确访问父类的属性?

iOS 11 上缺少 iOS 应用程序图标

ios - TouchesBegan 总是返回错误的 UIView

ios - 弹出框演示 Controller - View 周围有间距,不适合全宽度