滾動(dòng)通知,最近有人跟我說(shuō)滾動(dòng)通知怎么設(shè)置都不成功,就是類似于跑馬燈一樣的效果,其實(shí)這是一個(gè)很簡(jiǎn)單的功能。我們就用UIView提供的一個(gè)動(dòng)畫效果就可以。
//MARK:加動(dòng)畫
- (void)addAnimation
{
//先去除rollLabel的全部動(dòng)畫
[self.rollLabel.layer removeAllAnimations];
CGRectframe = self.rollLabel.frame;
frame.origin.x=self.hornButton.frame.size.width;
self.rollLabel.frame= frame;
floatinterval = self.rollLabel.frame.size.width/35;
[UIView beginAnimations:@"Animation"context:NULL];
[UIView setAnimationDuration:interval];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDelegate:weakSelf];
[UIView setAnimationRepeatAutoreverses:NO];
[UIView setAnimationRepeatCount:9999999];
frame = self.rollLabel.frame;
frame.origin.x= - self.rollLabel.frame.size.width;
self.rollLabel.frame= frame;
[UIView commitAnimations];
}

其中

這一句是根據(jù)rollLabel的長(zhǎng)度設(shè)置動(dòng)畫時(shí)長(zhǎng),所以如果rollLabel的內(nèi)容很多也可以正常使用。
這里只是加動(dòng)畫的其中一部分,加動(dòng)畫之前要先根據(jù)內(nèi)容長(zhǎng)度設(shè)置好rollLabel的width。