The basic idea of the gesture unlocking procedure

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 300, 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 add the write Button 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 the Custom view, depending on the current touch point, determine if you have touched a button

-Set the selected state of this button

-Record this button (added to the Selectedbuttons collection)

7.2 In the touchesmoved: method of the Custom view, depending on the current touch point, determine if you have touched a button

-Set the selected state of this button

-Record this button (added to the Selectedbuttons collection) and determine if the button is already selected = yes, and avoid adding it repeatedly.

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

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

8. Draw lines in the DrawRect: method

-Determine 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 self.selectedbuttons each button in the collection

2> judge 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 the button.

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

The color of the line

#define Stevezlinecolor [Uicolor colorwithred:0.0 green:170/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

Solve: (judge if there is no need to draw the button, then directly back)

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

Return

}

*/

9. In the touchesended: method, set the selected state of all buttons to NO, empty the Self.selectedbuttons collection, and redraw.

10. Add a tag for each button to determine if the gesture is 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 result returned by the proxy method, if YES, then execute the 9th step directly

-If returned as NO:

1> set All button selected states in Self.selectedbuttons to No, enabled is also set to No

2> is setting the line color to red

3> performing Redraw

4> after 0.5 seconds, perform step 9th.

11. Detail Handling

-Transparency issues

1> If you are creating UIView entirely from code, you will have problems drawing when you specify that the control's transparency (opaque = no) opaque is opaque.

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

-NSNumber Use problems

Do not use Int,nsinteger when string concatenation of integers, etc., use NSNumber

/**

Prevent the following code from appearing:

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

Cause: Because the iphone5s below are 32 bits, from IPhone5S began to become 64 bits, so nsinteger in iphone5s the following simulator is 32 bits, iphone5s (including) above are 64 bits

Resolution: (Unified use of NSNumber)

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

*/

-Nsinteger Use problems

1> General Object Properties, method parameters can be used using Nsinteger (can be guaranteed to use different integers on different platforms (32-bit, 64-bit))

2> local variables within a method, generally using int

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

The basic idea of the gesture unlocking procedure

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.