Realization of gesture unlocking

Source: Internet
Author: User

------------- Basic Ideas --------------

- 1. Build interface, nine Gongge algorithm

- 2. handle button check state

- 3. Draw lines between buttons

- 4. Draw a line between the finger and the button

- 5. determine if the unlock password is correct

------------- Basic Ideas --------------

1. Drag and drop the image material

2. set the background color of the controller view to the "HOMEBUTTOMBG" image after tiling the effect

Self. View.backgroundcolor = [Uicolor colorwithpatternimage:[uiimage imagenamed:@ "HOMEBUTTOMBG"];

3. Drag a UIView in the controller , set the width height to all , and set the constraint ( horizontal, vertical center alignment in the parent container ).

4. Customize a view to set the custom view associated with the view on the interface

5. Add a buttons property to the custom view , generate 9 UIButton in lazy loading , and write this Button are added to the view .

- Create each UIButton

-Set the background picture of each UIButton by default, background picture under selected , background image under disabled

6. Calculate the frame of each button in the Layoutsubviews method according to the nine Gongge way

7. When you touch a button , make the button's state change to selected

7.1 in the Touchesbegan: Method of Customizing View to determine whether a button is touched by the current touch point

- Set the selected State of this button

- Record this button ( added to the selectedbuttons collection )

7.2 in the touchesmoved: Method of Customizing View to determine whether a button is touched by the current touch point

- Set the selected State of this button

- Record this button ( added to the selectedbuttons collection ) and determine if the button is already selected = Yes , avoid repeating additions.

- at the same time, note the point to Currentpoint property of this touch .

* * Note : You must set the button here to disable interaction with the user (btn.userinteractionenabled = no;), No person touches the button after the finger , The button captures the touch event and does not trigger the view 's Touchesbegan: event.

8. Draw lines in the DrawRect: Method

- Judging if self . Selectedbuttons length is 0, then direct return does not need to draw any content

- If the self. Selectedbuttons length is not 0:

1> loop each button in the self. Selectedbuttons collection

2> Judging if it is the first button then move to the beginning (center point for the first button )

3> If it's not the first button, add the line segment directly to the center Point of this button

4> after the button is drawn, add a line segment to the Currentpoint at the end .

the color of the line

#define Stevezlinecolor [Uicolor colorwithred:0.0 Green:/255.0 Blue:255/ 255.0 Alpha:1.0]

/**

error :

<error>: void Cgpathaddlinetopoint (CGMUTABLEPATHREF, const cgaffinetransform *, CGFloat, cgfloat): no current Point.

reason :

There is no point in the Path object at the time of the first drawing

Resolve :( judgment if there are no buttons to draw , then return directly )

if (Self.selectedButtons.count = = 0) {

Return

}

*/

9. in the touchesended: method , set the selected status of all buttons to NOand clear Self . Selectedbuttons Collection , redraw.

Add a tag for each button to determine if the gesture was unlocked correctly

-Pass the unlocked password to the controller through the proxy , determine if the unlocking is correct in the controller, or return NO If the correct proxy method returns YES

- in the definition view , according to the results returned by the proxy method , if YES, then execute Step 9 directly

- if returned as NO:

1> Set all the buttons in the self. Selectedbuttons selected state to NO, enabled Also set to NO

2> set the line color to red

3> performing repainting

4> 0.5 seconds after the execution of step 9 .

detail Handling

- Transparency Issues

1> If the UIView is created entirely through code , when drawing , if the control is specified as transparent (opaque = NO)opaque Indicates an opacity , there is a problem with drawing.

2> If you want to be transparent , specify the color as clearcolor instead of opaque = no /c24>

-NSNumber Use problems

Do not use int, Nsinteger, etc. when string concatenation of integers, use nsnumber

/**

prevent the following code from appearing :

[Strpassword appendformat:@ "%d", [self.selectedbuttons[i] tag];

reason : because in the iphone5s below are all three , from the beginning of the iphone5s has become a bit , so Nsinteger in iphone5s the following simulator is the first , iphone5s(including) above are the

resolution : ( Unified use of NSNumber)

[Strpassword appendformat:@ "%@", @ ([self.selectedbuttons[i] tag]);

*/

-Nsinteger Use problems

1> General Object Properties, method parameters can be used using the Nsinteger ( can be guaranteed to use different integers on different platforms ( level, number ))

2 Local variables within the > method , generally using int

3> above is the code habit in Apple's official sample program

Realization of gesture unlocking

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.