Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Ios 无法使UIlabel文本在Xcode中闪烁_Ios_Objective C_Xcode - Fatal编程技术网

Ios 无法使UIlabel文本在Xcode中闪烁

Ios 无法使UIlabel文本在Xcode中闪烁,ios,objective-c,xcode,Ios,Objective C,Xcode,我一直试图让我的UILabel在Xcode中闪烁 但问题是它不会眨眼 这是我的密码: self.labelCountdownTime.alpha = 0.0; [UIView beginAnimations:nil context:nil]; [UIView setAnimationCurve:UIViewAnimationCurveLinear]; [UIView setAnimationDuration:1.0]; [UIView setAnimationRepeatCount:FLT_M

我一直试图让我的UILabel在Xcode中闪烁 但问题是它不会眨眼

这是我的密码:

 self.labelCountdownTime.alpha = 0.0;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.0];
[UIView setAnimationRepeatCount:FLT_MAX];
self.labelCountdownTime.alpha = 1.0;
[UIView commitAnimations];
是不是我做错了什么


谢谢

您可以使用
NSTimer
在UILabel中闪烁文本,如下所示:

NSTimer *timer = [NSTimer 
                      scheduledTimerWithTimeInterval:(NSTimeInterval)(1.0)
                            target:self 
                             selector:@selector(blink) 
                             userInfo:nil 
                             repeats:YES];
BOOL blinkStatus = NO;
选择器将调用此函数:

-(void)blink{
   if(blinkStatus == NO){
      yourLabel.alpha = 1.0;
     blinkStatus = YES;
   }else {
      yourLabel.alpha = 0.0;
      blinkStatus = NO;
   }
}
或者您可以使用
ui视图的
animationWithDuration
方法,如下所示:

self.yourLabel.alpha = 0;
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
        self.yourLabel.alpha = 1;
} completion:nil];

希望这能对您有所帮助。

我想您需要的是以下内容: 在控制器中创建计时器:

@property (strong, nonatomic) NSTimer *timer;
然后在需要启动计时器的地方启动计时器,比如在viewDidLoad

self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(toggleLabelAlpha) userInfo:nil repeats:YES];
这是选择器:

- (void)toggleLabelAlpha {

[self.labelCountdownTime setHidden:(!self.labelCountdownTime.hidden)];
}

试试这个?

这对我来说很好,请检查您是否正确连接了插座。但更好的方法是使用
UIView
animation块。它的连接方式是挑战性的。我是新手,你说使用UIView块是什么意思?见Khung291的答案,这是我提到的第三个代码。我试过了,但我的标签没有闪烁。你认为我实现的代码是错误的吗?你只是复制了我的代码,但是你没有看到标签名称不同-u-我刚刚尝试了两种方法,第一种方法出现了几个错误,第二种方法没有闪烁。我执行的代码错了吗?在那里更改标签名称!没有错误,应用程序生成成功,但uilabel不会闪烁。这就像是应用程序忽略了代码我该怎么做?抱歉,我是新手,只需单击线路左侧的1下,当我使用此应用程序时,应用程序就会崩溃:(很抱歉,我无法提供帮助。这在我以前的项目中适用。我确实在您发表评论的同时进行了编辑,因为我使用了self.label.hidden而不是self.labelcountdown.hidden,如果您不经编辑直接复制,可能会导致一些问题。)