Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone中的Autoscroll字幕标签_Iphone_Objective C_Uilabel_Marquee - Fatal编程技术网

iphone中的Autoscroll字幕标签

iphone中的Autoscroll字幕标签,iphone,objective-c,uilabel,marquee,Iphone,Objective C,Uilabel,Marquee,我有一个UILabel,我想像HTML中的字幕标签一样滚动,我该怎么做呢 #define LEFTSCROLLDIRECTION 0 #define RIGHTSCROLLDIRECTION 1 MarqueeLabel *marquee = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 10, 300, 30)]; label.scrollDirection = LEFTSCROLLDIRECTION; [self.view addSu

我有一个UILabel,我想像HTML中的字幕标签一样滚动,我该怎么做呢

#define LEFTSCROLLDIRECTION 0
#define RIGHTSCROLLDIRECTION 1

MarqueeLabel *marquee = [[MarqueeLabel alloc] initWithFrame:CGRectMake(10, 10, 300, 30)];
label.scrollDirection = LEFTSCROLLDIRECTION;
[self.view addSubview:marquee];
编辑 我已经找到了这门课,这门课一开始似乎很管用

但是这里面有一个缺点。。如果我在UINavigationController中向前导航,并在一段时间后弹出推送的ViewController,则autoScrollLabel将停止设置动画

AutoScrollLabel *autoScrollLabel = [[AutoScrollLabel alloc] init];
autoScrollLabel.text = @"Hi Mom!  How are you?  I really ought to write more often.";
autoScrollLabel.textColor = [UIColor yellowColor];

UILabel是一个UIView。有许多方法可以设置UIView的动画,但使用块可能是最好的选择

MarqueeLabel *marquee == ...
[UIView animateWithDuration:5.0 animations:^{ 
    CGRect frame = marquee.frame;
    frame.origin.x = -50.0f
    marquee.frame = frame;
}]:
这将具有在5秒内向左50像素“滚动”字幕的效果。您需要调整包含视图的大小以及选框的宽度

如果希望左侧的滚动条立即显示在右侧,可以使用第二个选框来实现这一点,该选框的x原点从320开始,因为第一个选框的x原点为0

查看开放源代码组件,实际上称为MarqueeLabel


它使这变得非常简单。

在界面生成器(Main.storyboard文件)中,我添加了一个UIView,为他提供了一个位置

我在ViewController.h中钩住了对象

IBOutlet UIView *marqueeView;
之后,在ViewController.m中,我写入了viewDidLoad方法:

MarqueeLabel *marqueeLabel = [[MarqueeLabel alloc] initWithFrame:CGRectMake(0, 0, 315, 20) duration:8.0 andFadeLength:10.0f];
marqueeLabel.text = @"marquee text.. this text will scroll";
[marqueeView addSubview:marqueeLabel];

我希望你能帮上忙。

很简单。试试下面的代码

    [UIView animateKeyframesWithDuration:5 delay:0 options:UIViewKeyframeAnimationOptionRepeat|UIViewAnimationOptionCurveLinear animations:^{
//_mlabel is my created sample label
        _mlabel.frame=CGRectMake(0-(self.view.frame.size.width), _mlabel.frame.origin.y, _mlabel.frame.size.width, _mlabel.frame.size.height);

    } completion:nil];

希望有帮助:)

您需要做一些额外的工作。应该不会太难。提示:查看UIView动画持续时间:动画:完成:当视图出现在屏幕上时,我会收到什么通知。。(在my UIView子类中)不确定当屏幕上出现UIView时是否会收到通知。这很复杂,如果视图离开屏幕,则在完成块中我会得到('BOOL finished'等于NO)。。这意味着动画没有发生,如果我仍然循环播放动画,这将成为一个非常繁重的过程,并且在那个时候取消动画意味着当该视图再次出现在屏幕上时,我将不得不重新启动动画