1

アプリケーションのパターン ロックを作成する必要があります。私がフォローしている例はここからです: http://blog.grio.com/2011/11/android-pattern-lock-on-iphone.html

ただし全画面ロックです。画面にはテキスト フィールドとボタンも必要なので、パターン ロックを画面の一部にのみ表示する必要があります。その中のいくつかの座標を変更し、パターンをそのサイズの 4 分の 1 に縮小しました。

例に示されているコードはpresentModalViewController:animated:、ビューがフルスクリーンで表示されることを意味します。ビューが全画面表示されないようにするにはどうすればよいですか? また、ストーリーボードを使用してコードを新しいプロジェクトに移植すると、NSInvalidArgument:認識されないセレクターがインスタンスに送信されるという例外が発生します

描画パターン:

- (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];
}

ビューコントローラー:

- (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];
}

助けてください!!

4

1 に答える 1