介紹
這是一款仿IOS10(就寢功能)的圓盤時(shí)間選擇器
項(xiàng)目演示

實(shí)現(xiàn)思路
以720度為一個(gè)周期,0~360°對應(yīng)0~12小時(shí),360°~720°對應(yīng)12~24小時(shí)

這里以”開始時(shí)間設(shè)置按鈕”為例來談?wù)勊幕瑒訉?shí)現(xiàn):
將”開始時(shí)間設(shè)置按鈕”作為點(diǎn)A,表盤中心作為點(diǎn)O,手指觸摸點(diǎn)作為點(diǎn)P.通過反正切公式可以計(jì)算出∠AOP的大小,然后隨著手指的位置不斷變化去更新點(diǎn)A的位置(即點(diǎn)A的角度).
// 坐標(biāo)系的直線表達(dá)式// 直線l1的表達(dá)式子:過鐘表中心點(diǎn)和開始控件中心點(diǎn)float a1 = mCenterY - mStartBtnCurY;float b1 = mStartBtnCurX - mCenterX;float c1 = mStartBtnCurY * mCenterX - mCenterY * mStartBtnCurX;double d1 = (a1 * eventX + b1 * eventY + c1) / (Math.sqrt(a1 * a1 + b1 * b1));// 直線l2的表達(dá)式:過鐘表中心點(diǎn)且垂直直線l1 float a2 = b1; float b2 = -a1; float c2 = -a2 * mCenterX - b2 * mCenterY; double d2 = (a2 * eventX + b2 * eventY + c2) / (Math.sqrt(a2 * a2 + b2 * b2));// 以l1為基準(zhǔn)線,順勢針半圓為0-180度,逆時(shí)針半圓為0-負(fù)180度 double moveDegree = Math.toDegrees(Math.atan2(d1, d2)); mStartDegree = (float) (mStartDegree + Math.floor(moveDegree)); mStartDegree = (mStartDegree < 0) ? mStartDegree + mDegreeCycle : mStartDegree % mDegreeCycle; refreshStartBtnPositon(); invalidate();
項(xiàng)目地址:Android仿IOS10圓盤時(shí)間選擇器
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答
圖片精選