title: pattern lock in iOS
body: <p>I need to make a pattern lock for my application. The example I am following is from here: <a href="http://blog.grio.com/2011/11/android-pattern-lock-on-iphone.html" rel="nofollow">http://blog.grio.com/2011/11/android-pattern-lock-on-iphone.html</a></p>
  
  <p>However it is a full screen lock. I need the pattern lock to appear in only a part of the screen, as my screen needs to have text fields and buttons as well. I have changed some coordinates in it and have brought the pattern down to one fourth of its size. </p>
  
  <p>The code given in the example uses <code>presentModalViewController:animated:</code> which means that the view shall be presented full screen. What should be done so that the view is NOT presented full screen? Also when I am porting the code to a new project with storyboards, I am getting the exception <code>NSInvalidArgument:</code> unrecognized selector sent to instance</p>
  
  <p>DrawPattern:</p>
  
  <pre><code>- (id)initWithFrame:(CGRect)frame
  {
      self = [super initWithFrame:frame];
      if (self) {
          // Initialization code
      }
  
      return self;
  }
  
  // Only override drawRect: if you perform custom drawing.
  // An empty implementation adversely affects performance during animation.
  - (void)drawRect:(CGRect)rect
  {
      NSLog(@"drawrect...");
  
      if (!_trackPointValue)
          return;
  
      CGContextRef context = UIGraphicsGetCurrentContext();
      CGContextSetLineWidth(context, 10.0);
      CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
      CGFloat components[] = {0.5, 0.5, 0.5, 0.8};
      CGColorRef color = CGColorCreate(colorspace, components);
      CGContextSetStrokeColorWithColor(context, color);
  
      CGPoint from;
      UIView *lastDot;
      for (UIView *dotView in _dotViews) {
          from = dotView.center;
          NSLog(@"drwaing dotview: %@", dotView);
          NSLog(@"\tdrawing from: %f, %f", from.x, from.y);
  
          if (!lastDot)
              CGContextMoveToPoint(context, from.x, from.y);
          else
              CGContextAddLineToPoint(context, from.x, from.y);
  
          lastDot = dotView;
      }
  
      CGPoint pt = [_trackPointValue CGPointValue];
      NSLog(@"\t to: pt = %f, pt = %f", pt.x, pt.y);
      CGContextAddLineToPoint(context, pt.x, pt.y);
  
      CGContextStrokePath(context);
      CGColorSpaceRelease(colorspace);
      CGColorRelease(color);
  
      _trackPointValue = nil;
  }
  
  
  - (void)clearDotViews {
      [_dotViews removeAllObjects];
  }
  
  
  - (void)addDotView:(UIView *)view {
      if (!_dotViews)
          _dotViews = [NSMutableArray array];
  
      [_dotViews addObject:view];
  }
  
  
  - (void)drawLineFromLastDotTo:(CGPoint)pt {
      _trackPointValue = [NSValue valueWithCGPoint:pt];
      [self setNeedsDisplay];
  }
  </code></pre>
  
  <p>ViewController:</p>
  
  <pre><code>- (void)viewDidLoad
  {
  
  
      // Do any additional setup after loading the view, typically from a nib.
  }
  - (void)viewWillAppear:(BOOL)animated
  {
      [super viewWillAppear:animated];
  }
  
  - (void)viewDidAppear:(BOOL)animated
  {
      [super viewDidAppear:animated];
  }
  
  - (void)viewWillDisappear:(BOOL)animated
  {
      [super viewWillDisappear:animated];
  }
  
  - (void)viewDidDisappear:(BOOL)animated
  {
      [super viewDidDisappear:animated];
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      // Return YES for supported orientations
      return NO;
  }
  
  
  - (void)lockEntered:(NSString*)key {
      NSLog(@"key: %@", key);
  
      if (![key isEqualToString:@"020508"]) {
          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                              message:@"Wrong pattern!"
                                                             delegate:nil
                                                    cancelButtonTitle:nil
                                                    otherButtonTitles:@"OK", nil];
          [alertView show];
      }
      else
          [self dismissModalViewControllerAnimated:YES];
  }
  
  
  - (IBAction)lockClicked:(id)sender {
      DrawPatternViewController *lockVC = [[DrawPatternViewController alloc] init];
      [lockVC setTarget:self withAction:@selector(lockEntered:)];
      [self presentModalViewController:lockVC animated:YES];
  }
  </code></pre>
  
  <p>Please help!!</p>