iOS實(shí)現(xiàn)波浪效果
本文實(shí)例為大家分享了iOS實(shí)現(xiàn)波浪效果的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
@interface ViewController () @property (strong, nonatomic) CADisplayLink *displayLink; @property (strong, nonatomic) CAShapeLayer *shapeLayer; @property (strong, nonatomic) UIBezierPath *path; @property (strong, nonatomic) CAShapeLayer *shapeLayer2; @property (strong, nonatomic) UIBezierPath *path2; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _shapeLayer = [CAShapeLayer layer]; _shapeLayer.frame = CGRectMake(0, 100, 375, 150); [self.view.layer addSublayer:_shapeLayer]; _shapeLayer2 = [CAShapeLayer layer]; _shapeLayer2.frame = CGRectMake(0, 100, 375, 150); [self.view.layer addSublayer:_shapeLayer2]; _shapeLayer.fillColor = [[UIColor yellowColor] colorWithAlphaComponent:0.3].CGColor; _shapeLayer2.fillColor = [[UIColor blueColor] colorWithAlphaComponent:0.3].CGColor; _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawPath)]; [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; } - (void)drawPath { static double i = 0; CGFloat A = 10.f;//A振幅 CGFloat k = 0;//y軸偏移 CGFloat ω = 0.03;//角速度ω變大,則波形在X軸上收縮(波形變緊密);角速度ω變小,則波形在X軸上延展(波形變稀疏)。不等于0 CGFloat φ = 0 + i;//初相,x=0時(shí)的相位;反映在坐標(biāo)系上則為圖像的左右移動(dòng)。 //y=Asin(ωx+φ)+k _path = [UIBezierPath bezierPath]; _path2 = [UIBezierPath bezierPath]; [_path moveToPoint:CGPointZero]; [_path2 moveToPoint:CGPointZero]; for (int i = 0; i < 376; i ++) { CGFloat x = i; CGFloat y = A * sin(ω*x+φ)+k; CGFloat y2 = A * cos(ω*x+φ)+k; [_path addLineToPoint:CGPointMake(x, y)]; [_path2 addLineToPoint:CGPointMake(x, y2)]; } [_path addLineToPoint:CGPointMake(375, -100)]; [_path addLineToPoint:CGPointMake(0, -100)]; _path.lineWidth = 1; _shapeLayer.path = _path.CGPath; [_path2 addLineToPoint:CGPointMake(375, -100)]; [_path2 addLineToPoint:CGPointMake(0, -100)]; _path2.lineWidth = 1; _shapeLayer2.path = _path2.CGPath; i += 0.1; if (i > M_PI * 2) { i = 0;//防止i越界 } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- iOS實(shí)現(xiàn)百度外賣頭像波浪的效果
- iOS毛玻璃效果的實(shí)現(xiàn)及圖片模糊效果的三種方法
- iOS開發(fā)之路--仿網(wǎng)易抽屜效果
- IOS等待時(shí)動(dòng)畫效果的實(shí)現(xiàn)
- IOS使用UICollectionView實(shí)現(xiàn)無限輪播效果
- iOS開發(fā)中的ViewController轉(zhuǎn)場(chǎng)切換效果實(shí)現(xiàn)簡(jiǎn)介
- IOS實(shí)現(xiàn)圓形圖片效果的兩種方法
- iOS開發(fā)中視圖的下拉放大和上拉模糊的效果實(shí)現(xiàn)
- iOS自定義提示彈出框?qū)崿F(xiàn)類似UIAlertView的效果
相關(guān)文章
IOS 圖文混排(CoreText.framework)詳解及實(shí)例
這篇文章主要介紹了IOS 圖文混排(CoreText.framework)詳解及實(shí)例的相關(guān)資料,這里對(duì)IOS 的圖文混排進(jìn)行了詳細(xì)介紹,并附代碼實(shí)例,和實(shí)現(xiàn)效果圖,需要的朋友可以參考下2016-11-11IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題
這篇文章主要介紹了IOS倒計(jì)時(shí)設(shè)置UIButton標(biāo)題title的抖動(dòng)問題,在發(fā)送驗(yàn)證碼后,button狀態(tài)需要變?yōu)閐isable,每隔一秒顯示倒計(jì)時(shí)時(shí)間,下面通過本文給大家介紹設(shè)置方法,一起看看吧2016-12-12IOS開發(fā)之JSON轉(zhuǎn)PLIST實(shí)例詳解
這篇文章主要介紹了IOS開發(fā)之JSON轉(zhuǎn)PLIST實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2016-11-11iOS制作framework靜態(tài)庫(kù)圖文教程
這篇文章主要為大家詳細(xì)介紹了iOS制作framework靜態(tài)庫(kù)圖文教程,感興趣的小伙伴們可以參考一下2016-08-08iOS開發(fā)中UITableview控件的基本使用及性能優(yōu)化方法
這篇文章主要介紹了iOS開發(fā)中UITableview控件的基本使用及性能優(yōu)化方法,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2015-12-12iOS開發(fā)之tableView cell的展開收回功能實(shí)現(xiàn)代碼
本文介紹了iOS開發(fā)之tableView cell的展開收回功能實(shí)現(xiàn)代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01iOS 解決UICollectionView 計(jì)算 Cell 大小的問題
本文主要介紹iOS UICollectionView,這里給大家一個(gè)實(shí)例代碼作為參考,并指出經(jīng)常遇到的問題和解決辦法,希望能幫助有需要的小伙伴2016-07-07