Unlock the Swift version gesture imitation of Alipay, and provides a method of parameter modification, development can solve all the gesture to unlock the project development


Unlock the Swift version gesture imitation of Alipay, and provides a method of parameter modification, development can solve all the gesture to unlock the project development

Design sketch

Unlock the Swift version gesture imitation of Alipay, and provides a method of parameter modification, development can solve all the gesture to unlock the project development
2016-08-30 19_29_03.gif

Cause of this project

  • Personal learning OC version of the gesture to unlock, feel only the source code, not much effect, so it will be completely copied into the magic of Swift
  • Source OC version gesture unlock
  • For a deeper understanding of the wonderful Swift

Project profile

  1. Package configuration parameter GYTools GYCircleConst: system
    , wrong language tips, background color and so on, can according to their own projects need to be modified
    GYCircleView: View
    sign a single round GestureViewController: two case set password and login VC
    GestureVerifyViewController: to verify and modify the VC gesture gesture
  2. GYCircleView:
    core implementation method of the realization of the principle: each circle is added to a string of tag splicing (which can be transmitted to the server to save the local project) compared to began – //MARK:- moved – end override func gesture method touchesBegan (touches: Set< UITouch&gt, withEvent; event: UIEvent? GestureEndResetMembers (currentPoint)) {CGPointZero = let = touch (touches as NSSet (let).AnyObject) point = touch?.locationInView (self) (subviews as NSArray) {.EnumerateObjectsUsingBlock (circle, IDX, stop) in let CIR as GYCircle = circle (cir.frame, CGRectContainsPoint if! Point! = CircleState.CircleStateSelected) {cir.state self.circleSet?.addObject (CIR) print View tag:/ (“add (cir.tag)”}) In the last one} / / array object circleSetLastObjectWithState (CircleState.CircleStateLastOneSelected) setNeedsDisplay (override)} func touchesMoved (touches: Set< UITouch&gt, withEvent; event: UIEvent? CGPointZero) {currentPoint = touch = let (touches as NSSet) (.AnyObject) / / get pointcoordinates let point = touch where.LocationInView sign (self)? (subviews as NSArray) {.EnumerateObjectsUsingBlock (circle, IDX, stop) in let CIR / / I = circle as! GYCircle if CGRectContainsPoint (cir.frame point!) {/ / here idiotic self.circleSet?.containsObject (CIR) = nil! / / determine the array is contained in this view contains no added does not contain added if self.circleSet.ContainsObject (CIR) {! / / print (“add View tag:/ (cir.tag)”) / / self.circleSet?.addObject (CIR) / self.calAngleAndconnectTheJumpedCircle (else)} {self.circleSet?.addObject (CIR) / / move in the process of connection (including processing jump line) self.calAngleAndconnectTheJumpedCircle (else)}} {self.currentPoint}} (guard = point = self.circleSet! Nil else (self.circleSet) {return}! {.EnumerateObjectsUsingBlock (circle as NSArray), IDX, stop) in let circlel = circle as circlel.state = CircleState.CircleStateSelected / GYCircle! If the login or verification The original password is changed into gesture state corresponding to the if self.type self.circleSetLastObjectWithState CircleViewType.CircleViewTypeSetting! = {circlel.state = CircleState.CircleStateLastOneSelected}} / / the last object in the array (CircleState.CircleStateLastOneSelected) setNeedsDisplay (override)} func touchesEnded (touches: Set< UITouch&gt, withEvent; event: UIEvent? False guard) {self.hasClean = self.circleSet = nil {return else! Gesture = self.getGestureResultFromCircleSet let} (self.circleSet!) let length = gesture.length if length = = 0 {return} / / switch self.type gesture rendering results {case CircleViewType.CircleViewTypeSetting:! GestureEndByTypeSettingWithGesture (gesture, length: CGFloat (length) break case CircleViewType.CircleViewTypeLogin: gestureEndByTypeLoginWithGesture (gesture), length: CGFloat (length) case CircleViewType.CircleViewTypeVerify: gestureEndByTypeVerifyWithGesture (gesture), length: CGFloat (length))} / / after the back gesture is wrong redraw, depending on whether the delay empty array and recovery errorToDisplay (//MARK:-)} state each add a a circle is calculated in a direction of func {if (calAngleAndconnectTheJumpedCircle) circleSet = nil || circleSet?.count &lt = 1; {return} / / remove the last object let lastOne.LastObject = circleSet? As! GYCircle / / second last let lastTwo = circleSet.ObjectAt? Index (self.circleSet!.count – 2) as! GYCircle / / second from the calculated position let last_1_x = lastOne.center.x let last_1_y = lastOne.center.y let last_2_x = lastTwo.center.x let last_2_y = lastTwo.center.y //1. to calculate the angle (arctan function) let angle = atan2 (Float (last_1_y) – Float (last_2_y), Float (last_1_x) – Float (last_2_x)) + Float (M_PI_2) lastTwo.angle = CGFloat (angle) print (lastTwo.angle) //2. let = centerPointWithPointOneandTwo center jump connection (lastOne.center, pointTwo: lastTwo.center) let centerCircle = self.enumCircleSetToFindWhichSubviewContainTheCenterPoint (Center) if centerCircle! = nil {/ / to skip the circle array, his position is second from if (self.circleSet!.containsObject! (centerCircle!)) {/ / into the array self.circleSet?.insertObject (centerCircle!, atIndex: (self.circleSet?.count)! – 1) / / specifies that the round angle and the same angle. Otherwise it will cause the shift centerCircle?.angle = lastTwo.angle}} 3 to achieve the call
Switch sender.tag {case 1: / / let gesture = GestureViewController password set gestures (gesture.type = GestureViewControllerType.Setting) navigationController?.pushViewController (gesture, animated: true) break case 2: print (GYCircleConst.getGestureWithKey / log gesture password (gestureOneSaveKey)) if GYCircleConst.getGestureWithKey (gestureFinalSaveKey) = nil {let! GestureVC = GestureViewController (gestureVC.type) = GestureViewControllerType.Login (gestureVC.PushViewController navigationController? Animated: else, true)} {let alertView = UIAlertView title: ("message:" reminder ", not set gesture password, Whether to set the "delegate:, self, cancelButtonTitle:", otherButtonTitles: "Cancel" set up ") (alertView.show) break case 3:} / / gestureVerifyVc = GestureVerifyViewController let gesture password verification (navigationController)?.pushViewController (gestureVerifyVc, animated: true) break case 4: let gestureVerifyVc / / modify gesture password = GestureVerifyViewController (gestureVerifyVc.isToSetNewGesture) navigationController (.PushViewController = true? GestureVerifyVc animated:, true break)

4 meeting of the swift
1 nil
) around the pit 2)
GET and SET Swift to rewrite 3) init initialization
4) some optional values will lead to the collapse of uninitialized nil
finally, offer the source address for Star, we learn together, 3Q.