显示隐藏的UIView两次,每5秒使用的NSTimer [英] Show Hide UIView Twice Every 5 Seconds Using NSTimer
本文介绍了显示隐藏的UIView两次,每5秒使用的NSTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UIView添加到视图控制器。我想让它闪烁两次,每5秒。
I have a UIView added to a view controller. I want to make it blink twice every 5 seconds.
以下code,使眨眼的UIView和关闭每隔1秒:
The following code makes the UIView blink on and off every 1 second:
-(void) showHideView{
[UIView animateWithDuration:1
delay:5
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.myview.alpha = 0;
}
completion:^(BOOL finished){
[UIView animateWithDuration:1
delay:5
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
self.myview.alpha = 1;
}
completion:nil
];
}
];
}
我怎样才能让UIView的闪烁两次,每5秒? (即,两个闪烁的脉冲)
How can I make the UIView blink twice every 5 seconds? (i.e. a pulse of two blinks)
推荐答案
既然你举报这与iOS7,我可能会建议关键帧动画:
Since you've flagged this with iOS7, I might suggest keyframe animation:
[UIView animateKeyframesWithDuration:2.5 delay:0.0 options:UIViewKeyframeAnimationOptionRepeat animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:0.25 animations:^{
self.myview.alpha = 0.0;
}];
[UIView addKeyframeWithRelativeStartTime:0.5 relativeDuration:0.25 animations:^{
self.myview.alpha = 1.0;
}];
} completion:nil];
扭捏总持续时间(频率重复循环),相对开始时间(总时间的百分比),相对持续时间(再次,总时间的百分比),你认为合适。
Tweak total duration (how often the cycle repeats), the relative start times (a % of the total duration), and the relative duration (again, a % of the total duration) as you see fit.
这篇关于显示隐藏的UIView两次,每5秒使用的NSTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文