识别屏幕locking的滑动模式n解锁ios

我想创build一个用于locking的滑动模式并解锁屏幕(不用摘下手指即可滑动)。 我如何使用UISwipeGestureRecognizer来做到这一点。 当我再次尝试login时,我想保存并匹配它。 我该如何保存? 作为一个形象或别的东西? 请帮助我这个。 谢谢。

iOS版iPhone上的Android模式locking

iOS的模式locking类似于Android中的模式locking

当你谈论“模式”时,你的意思是什么,你到底想要保存什么?

您应该使用UIPanGestureRecognizer因为滑动只是一个快速翻转手势,平移是一个受控的移动,您可以跟踪整个距离。

这是我如何处理它,从右向左移动(与锁屏相反的方向):

 - (IBAction)slide:(UIPanGestureRecognizer *)gesture { CGPoint translate = [gesture translationInView:gesture.view]; translate.y = 0.0; // Just doing horizontal panning if (gesture.state == UIGestureRecognizerStateChanged) { // Sliding left only if (translate.x < 0.0) { self.slideLane.frame = [self frameForSliderLabelWithTranslate:translate]; } } else if ([gesture stoppedPanning]) { if (translate.x < 0.0 && translate.x < -(gesture.view.frame.size.width / 2.5)) { // Panned enough distance to unlock } else { // Movement was too short, put it back again NSTimeInterval actualDuration = [self animationDuration:0.25 forWidth:gesture.view.frame.size.width withTranslation:(-translate.x)]; [UIView animateWithDuration:actualDuration delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ self.slideLane.frame = [self frameForSliderLabelWithTranslate:CGPointZero]; } completion:^(BOOL finished) { }]; } } } - (CGRect)frameForSliderLabelWithTranslate:(CGPoint)translate { return CGRectMake(translate.x, self.slideLane.frame.origin.y, self.slideLane.bounds.size.width, self.slideLane.bounds.size.height); } 

因为我不在乎为什么一个手势已经停止,所以我添加了这个类别来使else-if子句更具可读性。 不过,这是可选的:

 @implementation UIPanGestureRecognizer (Stopped) - (BOOL)stoppedPanning { return ( self.state == UIGestureRecognizerStateCancelled || self.state == UIGestureRecognizerStateEnded || self.state == UIGestureRecognizerStateFailed); } @end 

理想情况下,你会考虑到运动的速度,因为快速轻弹到正确的方向就足够了。 就我而言,我希望用户移动块,无论多快。