支付寶裡有個刮刮樂中獎, 和大街小巷裡的類似彩票刮刮樂的效果一樣。
一、實現思路
其實很簡單的三步:
1. 展示刮出來的效果的view: 即刮開後刮刮樂效果展示-顯示的文字label
2. 設定遮擋在外面的image(被刮的)
3. 在touchesmoved方法裡面實現操作: 刮開獲取文字
二、程式實現
雖然思路簡單,但是還需要注意:
1. 這兩個控制項的位置切記要相同!
2. 一定要先建立下面的展示刮出來的效果控制項的, 再建立上面的被刮的控制項!
下面就直接上核心**!
展示刮開出來的效果:顯示的文字 label
uilabel *showlabel = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 274, 145)];
showlabel.center = self.view.center;
showlabel.backgroundcolor = [uicolor redcolor];
showlabel.textcolor = [uicolor yellowcolor];
showlabel.text = @"恭喜你中獎了";
showlabel.font = [uifont systemfontofsize:30];
showlabel.textalignment = nstextalignmentcenter;
[self.view addsubview:showlabel];
2. 設定遮擋在外面的image(被刮的)
uiimageview *scratchedimg = [[uiimageview alloc] initwithframe:showlabel.frame];
scratchedimg.image = [uiimage imagenamed:@"scratched"];
[self.view addsubview:scratchedimg];
self.scratchedimg = scratchedimg;
3. 在touchesmoved方法裡面實現操作
- (void)touchesmoved:(nsset *)touches withevent:(uievent *)event {
// 觸控任意位置
uitouch *touch = touches.anyobject;
// 觸控位置在上的座標
cgpoint cententpoint = [touch locationinview:self.scratchedimg];
// 設定清除點的大小
cgrect rect = cgrectmake(cententpoint.x, cententpoint.y, 20, 20);
// 預設是去建立乙個透明的檢視
uigraphicsbeginimagecontextwithoptions(self.scratchedimg.bounds.size, no, 0);
// 獲取上下文(畫板)
cgcontextref ref = uigraphicsgetcurrentcontext();
// 把imageview的layer對映到上下文中
[self.scratchedimg.layer renderincontext:ref];
// 清除劃過的區域
cgcontextclearrect(ref, rect);
// 獲取
uiimage *image = uigraphicsgetimagefromcurrentimagecontext();
// 結束的畫板, (意味著在上下文中消失)
uigraphicsendimagecontext();
self.scratchedimg.image = image;
三、壓縮檔案截圖及執行效果
1、壓縮檔案截圖:
2、執行時的截圖
四、其他補充
介面性問題可以根據自己專案需求調整即可, 具體可參考**, 專案能夠直接執行!
iOS 仿支付寶密碼支付
位址如下 問題二 怎麼做到輸入密碼的時候黑點顯示或消失一致 void passwordfielddidchange uitextfield field if passwordfield.text length 6 else add the actions.alertcontroller addact...
iOS 仿支付寶刮刮樂效果
仿支付寶刮刮樂效果,可以按照自己需求更改展示刮出來的效果的view 即刮開後刮刮樂效果展示 支付寶裡有個刮刮樂中獎,和大街小巷裡的類似彩票刮刮樂的效果一樣。一 實現思路 其實很簡單的三步 二 程式實現 雖然思路簡單,但是還需要注意 1.這兩個控制項的位置切記要相同 2.一定要先建立下面的展示刮出來的...
iOS仿支付寶輸入支付密碼框
類似於下圖這樣的輸入框,並實現其功能 實現這個頁面,其中輸入框部分為核心問題,僅針對輸入框部分進行解讀 下面 只看其功能不看其位置資訊 toptextfield uitextfield alloc initwithframe cgrectmake 0,wayline.bottom,passview....