思考
創建壹個視圖作為所有內容的父控件,並將其添加到上面的標簽中,作為顯示文本的載體。
ui label * content label =[[ui label alloc]init];[content label sizeToFit];content label . background color =[ui color clear color];_ contentLabel = contentLabel【self add subview:self . content label】;
給內容視圖的`層添加壹個蒙版層,將其範圍設置為整個視圖的邊界,這樣視圖之外的內容就不會顯示了。
CAShapeLayer * mask layer =[CAShapeLayer layer];mask layer . path =[UIBezierPath bezierPathWithRect:self . bounds]。CGPathself . layer . mask = mask layer;
向標簽添加動畫
CAKeyframeAnimation * key frame =[CAKeyframeAnimation動畫];key frame . key path = @ " transform . translation . x ";keyFrame.values = @[@(0),@(-space),@(0)];key frame . repeat count = NSIntegerMax;key frame . duration = self . speed * self . content label . text . length;key frame . timing functions = @[[CAMediaTimingFunction function with name:kCAMediaTimingFunctionEaseInEaseOut],[CAMediaTimingFunction function with control points:0:0:0.5:0.5]];keyFrame.delegate = self[self . content label . layer add animation:key frame forKey:nil];
施用方式
//Create CFDynamicalLabel * test label =[[CFDynamicalLabel Alloc]initwithframe:cgrectmake(100,300,180,21)];//設置滾動速度testLabel.speed = 0.6[self . view addSubview:test label];//設置基本屬性testLabel.text = @“不想說再見,永遠不說再見,越長大越孤獨”;test label . text color =[ui color yellow color];test label . font =[ui font system font of size:23];test label . background color =[ui color gray color];
摘要
這就是本文的全部內容。希望這篇文章的內容能給妳的學習或者工作帶來壹些幫助。有問題可以留言交流。