自定義封裝進度提示框《MrLoadView》

2021-07-09 07:20:39 字數 3835 閱讀 8821

封裝mrloadview類:

**效果圖:**

// 關鍵**

/** 初始化ui布局

*/func setui()

// 底部的灰色layer

let bottomshapelayer = cashapelayer()

bottomshapelayer.strokecolor = self.bottomcolor.cgcolor

bottomshapelayer.fillcolor = uicolor.clearcolor().cgcolor

bottomshapelayer.linewidth = mrshapelayerlinewidth

// 圖形的路徑

bottomshapelayer.path = uibezierpath(roundedrect: cgrect(x: mrshapelayermargin, y: 0, width: mrshapelayerwidth, height: mrshapelayerwidth), cornerradius: mrshapelayerradius).cgpath

self.layer.addsublayer(bottomshapelayer)

// 橘黃色的layer

let ovalshapelayer = cashapelayer()

ovalshapelayer.strokecolor = self.animationcolor.cgcolor

ovalshapelayer.fillcolor = uicolor.clearcolor().cgcolor

ovalshapelayer.linewidth = mrshapelayerlinewidth

// 分割點效果

ovalshapelayer.linedashpattern = [6, 3]

ovalshapelayer.path = uibezierpath(roundedrect: cgrect(x: mrshapelayermargin, y: 0, width: mrshapelayerwidth, height: mrshapelayerwidth), cornerradius: mrshapelayerradius).cgpath

self.layer.addsublayer(ovalshapelayer)

// 起點動畫

let strokestartanimation = cabasicanimation(keypath: "strokestart")

strokestartanimation.fromvalue = -1

strokestartanimation.tovalue = 1.0

// 終點動畫

let strokeendanimation = cabasicanimation(keypath: "strokeend")

strokeendanimation.fromvalue = 0.0

strokeendanimation.tovalue = 1.0

// 組合動畫

let animationgroup = caanimationgroup()

animationgroup.animations = [strokestartanimation, strokeendanimation]

animationgroup.duration = (double)(mranimationdurationtime)

animationgroup.repeatcount = (float)(cgfloat.max)

// 設定儲存動畫的最新狀態

animationgroup.fillmode = kcafillmodeforwards

// 設定動畫執行完畢之後不刪除動畫

animationgroup.removedoncompletion = false

// 新增核心動畫到layer

ovalshapelayer.addanimation(animationgroup, forkey: nil)

self.titlelabel = uilabel()

self.titlelabel!.frame = cgrectmake(0, mrshapelayerwidth + 5, mrloadingviewwidth + 10, 30)

self.titlelabel!.numberoflines = 0

self.titlelabel!.text = self.message

self.titlelabel!.textcolor = mrloadingtextcolor

self.titlelabel!.font = uifont.systemfontofsize(12)

self.titlelabel!.textalignment = nstextalignment.center

self.addsubview(self.titlelabel!)

}/**

顯示載入動畫

*/func showloadingview()

isshowing = true

self.addselfviewtowindow()

}/**

關閉載入動畫

*/func dismissloadingview()

isshowing = false

self.removefromsuperview()

}/**

顯示載入動畫(帶毛玻璃效果)

*/func showloadingviewwithblur()

isshowing = true

self.addselfviewtowindow()

// 拿到主視窗

// view的x

let viewcenterx: cgfloat = cgrectgetwidth(uiscreen.mainscreen().bounds)/2

// view的y

let viewcentery: cgfloat = cgrectgetheight(uiscreen.mainscreen().bounds)/2

// 初始化模糊效果

blurview = uivisualeffectview(effect: uiblureffect(style: uiblureffectstyle.light))

blurview?.layer.cornerradius = 10

blurview?.layer.maskstobounds = true

blurview?.frame = cgrectmake(0, 0, 100, 100)

blurview?.center = cgpointmake(viewcenterx, viewcentery)

/**新增毛玻璃效果

*/window?.insertsubview(blurview!, belowsubview: self)

}/**

將本身新增到主視窗

*/func addselfviewtowindow()

}

使用測試:

func showloadview(sender: uibutton) 

func dismissloadview(sender: uibutton)

override func touchesbegan(touches: set

, withevent event: uievent?)

自定義模態提示框

關於android中模態提示框的問題 因為專案最新的效果圖,中提示框為模態的,先前用的toast,雖然可以實現功能,但是提示框後面並沒有模態框那樣的灰色半透明蒙板,現把 給大家參考 customer dialog.xml android orientation horizontal android ...

自定義彈出提示框

把confirm提示框的 確定 和 取消 按鈕,修改一下文字,並進行相應的按鈕事件。生成html var generatehtml function type,title,msg html 必須先將 html新增到body,再設定css樣式 生成css var generatecss functio...

自定義的提示框

上面橙色的就是提示框,position是fixed的,在這個編寫過程中確實遇到了難點,那就是 我的頻道 是iframe,而我們如果在iframe中直接加入這個js,那麼它的fixed只是相對於iframe的,而不是當前的視窗,所以,我們要在iframe內部回應,並且在頂層響應,這裡上瀏覽器找了好久的...