【问题标题】:UILabel to animate left and back again from rightUILabel 从右侧向左和向后再次设置动画
【发布时间】:2016-04-29 07:03:36
【问题描述】:

所以我想要实现的是有一个 UILabel 文本,它应该像 LED 广告牌一样动画,展示新闻和商场外的各种其他文本等。UILabel 不应该改变位置,但其中的文本应该从当前移动定位到 UILabel 的左侧边界并从右侧再次返回,有点像队列。示例文本是:

动画前:

“我想实现这个……”

动画期间:

"想实现这个...我愿意"

“实现这个...我想实现” 等等

只要我希望动画保留,这应该会一直持续下去,可能永远。

请任何帮助都会创造奇迹。谢谢

【问题讨论】:

    标签: ios iphone swift swift2 xcode7


    【解决方案1】:
    pod MarqueeLabel
    

    MarqueeLabel 提供此功能。只需将标签的类名设置为 MarqueeLabel,如下所示:-

    @IBOutlet weak var lblLocation: MarqueeLabel!
    

    根据您的要求设置属性:-

    1. 持续时间
    2. 渐变长度
    3. 选框类型

    【讨论】:

      【解决方案2】:

      这是一个简单的解决方案:

      - (void)viewDidLoad {
          [super viewDidLoad];
      
          self.label.text = @"I would like to implement this...";
          self.timer = [NSTimer timerWithTimeInterval:0.3f target:self
                                             selector:@selector(animateText)
                                             userInfo:nil
                                              repeats:YES];
          [[NSRunLoop mainRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
      }
      
      - (void)animateText{
          NSMutableString *str = [NSMutableString stringWithString:[self.label.text substringFromIndex:1]];
          [str appendString:[self.label.text substringToIndex:1]];
          self.label.text = str;
      }
      

      【讨论】:

      • 请在 Swift 中使用一些东西。ObjectiveC 的选择器非常简单;和 pfft,swift 是一个恐怖故事:P
      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-28
      相关资源
      最近更新 更多