系統原生載入展示——uiactivityindicatorview&uiprogressview
開源專案svprogresshud&mbprogresshud
介紹 svprogresshud展示載入用到cashapelayer
結合cashapelayer中strokestart和strokeend繪製動畫
- (void)setupactivityindicators
- (void)stopactivityindicator
- (void)setupprogressview
- (void)finishprogress
svprogresshud
- (void)viewdidload );
}
[svprogresshud show];
[svprogresshud showwithmasktype:svprogresshudmasktypeblack];
[svprogresshud showwithstatus:@"waiting..."];
[svprogresshud showwithstatus:@"檔案生成中..." masktype:svprogresshudmasktypegradient];
[svprogresshud showimage:[uiimage imagenamed:@"angle-mask.png"] status:@"已收藏"];
[svprogresshud showsuccesswithstatus:@"已儲存" masktype:svprogresshudmasktypeblack];
[svprogresshud showerrorwithstatus:@"失敗" masktype:svprogresshudmasktypeblack];
[svprogresshud dismiss];
cashapelayer和mask結合實現小圓圈,masklayer相關見calayer屬性mask
- (void)setupmask
因為svprogresshud需要有動畫不停的旋轉,這邊是通過兩個動畫完成:旋轉動畫和乙個動畫組。
1.旋轉動畫
// 設定動畫的延遲及型別
nstimeinterval animationduration = 1;
camediatimingfunction *linearcurve = [camediatimingfunction functionwithname:kcamediatimingfunctionlinear];
cabasicanimation *animation = [cabasicanimation animationwithkeypath:@"transform.rotation"];
// 注意value型別為id型別
animation.fromvalue = (id) 0;
animation.tovalue = @(m_pi*2);
animation.duration = animationduration; animation.timingfunction = linearcurve;
// removedoncompletion指動畫之後保持動畫完成的狀態
animation.removedoncompletion = no;
animation.repeatcount = infinity;
animation.fillmode = kcafillmodeforwards;
animation.autoreverses = no;
// 將動畫加到mask上
[shapelayer.mask addanimation:animation forkey:@"rotate"];
2.動畫組,會有一段小亮點在轉動;涉及到strokestart和strokeend,可以看下一節
// 建立動畫組,並設定相關屬性
caanimationgroup *animationgroup = [caanimationgroup animation];
animationgroup.duration = animationduration;
animationgroup.repeatcount = infinity;
animationgroup.removedoncompletion = no;
animationgroup.timingfunction = linearcurve;
// strokestart動畫
cabasicanimation *strokestartanimation = [cabasicanimation animationwithkeypath:@"strokestart"];
strokestartanimation.fromvalue = @0.015;
strokestartanimation.tovalue = @0.515;
// strokeend動畫
cabasicanimation *strokeendanimation = [cabasicanimation animationwithkeypath:@"strokeend"];
strokeendanimation.fromvalue = @0.485;
strokeendanimation.tovalue = @0.985;
// 將動畫加到動畫組
animationgroup.animations = @[strokestartanimation, strokeendanimation];
[shapelayer addanimation:animationgroup forkey:@"progress"];
執行結果
旋轉載入.gif
strokestart和strokeend動畫
做了個測試,乙個小紅圈分別設定strokestart和strokeend,執行會發現
結果截圖(按照順序)
1.對strokestart應用動畫時:
2.對strokeend應用動畫時:
mbprogresshud
- (ibaction)clicktextwithloadingbtn:(id)sender
- (ibaction)clickprogressonebtn:(id)sender ;
*/[hud showanimated:yes
whileexecutingblock:^}
completionblock:^];
}- (ibaction)clickprogresstwobtn:(id)sender
} completionblock:^];
}- (ibaction)clickcustombtn:(id)sender
- (ibaction)clicktextbtn:(id)sender
iOS貝塞爾曲線簡單使用
建立和使用path物件步驟 1 重寫view的drawrect方法 2 建立uibezierpath的物件 3 使用方法movetopoint 設定初始點 4 根據具體要求使用uibezierpath類方法繪圖 比如要畫線 矩形 圓 弧?等 5 設定uibezierpath物件相關屬性 比如line...
ios 貝塞爾曲線方法解釋
1 根據乙個矩形畫曲線 uibezierpath bezierpathwithrect cgrect rect 2 根據矩形框的內切圓畫曲線 uibezierpath bezierpathwithovalinrect cgrect rect 3 根據矩形畫帶圓角的曲線 uibezierpath be...
iOS實現貝塞爾曲線動畫
效果如圖 仿美人相機,手勢滑動隱藏頂部view。為了方便講解,將螢幕分為幾個區域,如圖 在拖動過程中 1 拖動距離小於minmovedistance,貝賽爾曲線發生形變 2 拖動大於minmovedistance,整個view開始下移 在鬆開手時 1 拖動距離小於minmovedistance,未發...