1

私は、ユーザーがアプリに保存されているデータにアクセスするためにパスワードを入力する必要がある「ロック画面」を必要とするアプリに取り組んでいます。

このロック画面は、アプリが起動されていないとき、およびユーザーが数分間操作を行わなかった後に表示されます。

現在、ストーリーボードに別のUIViewControllerがあり、ストーリーボードの他のビューに接続されていません。[セルフストーリーボード]にinstantiateViewControllerWithIdentifierを送信することで、このビューコントローラーにアクセスできることを理解しています。ただし、これはアプリデリゲートからは機能しません。

ただし、アプリデリゲートがデータベースを開こうとする前に、アプリデリゲートからロック画面を呼び出す必要があります。

これを実装するための良い方法は何でしょうか?

4

3 に答える 3

4

これはおそらく遅い回答ですが、Storyboard を使用している顧客の 1 人に同じ要件を実装する必要がありました。ここからプロジェクト全体をダウンロードできます。うまくいけば、これは誰かを助けるかもしれません。

2 つの Viewcontrollers を作成しました。1 つは MainView で、もう 1 つは 4 桁のコードを無視する必要があります。MainView と BlockKeypadViewController の間にモーダル セグエを作成し、「lockItSegue」と名付けました。MainView に、「lockIt」メソッドを呼び出す RoundRectButton を挿入しました。このメソッドは、セグエ「lockItSegue」を実行するだけです。

- (IBAction)lockIt:(id)sender 
{
    [self performSegueWithIdentifier:@"lockItSegue" sender:self];
}

BlockKeypadViewController.h で、作成しました

//
//  BlockKeypadViewController.h
//  Consultablet
//
//  Created by EDGARD AGUIRRE ROZO on 22/03/13.
//  Copyright (c) 2013 Colombia Creative Software. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>

@interface BlockKeypadViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *wrongCodeLabel;//*codigoIncorrectoLabel;
@property (strong, nonatomic) IBOutlet UILabel *tryAgainLabel;//*trateNuevamenteLabel;

@property (strong, nonatomic) IBOutlet UILabel *digit1;//*caracter1;
@property (strong, nonatomic) IBOutlet UILabel *digit2;//*caracter2;
@property (strong, nonatomic) IBOutlet UILabel *digit3;//*caracter3;
@property (strong, nonatomic) IBOutlet UILabel *digit4;//*caracter4;
@property int counter;//contador;
@property int codeIn;//claveIngresado;
@property int unlockCode;//claveDesbloqueo;
-(void) calculate:(int)number;//calcular:(int)numero;
- (IBAction)one:(id)sender;//uno:(id)sender;
- (IBAction)two:(id)sender;//dos:(id)sender;
- (IBAction)three:(id)sender;//tres:(id)sender;
- (IBAction)four:(id)sender;//cuatro:(id)sender;
- (IBAction)five:(id)sender;//cinco:(id)sender;
- (IBAction)six:(id)sender;//seis:(id)sender;
- (IBAction)seven:(id)sender;//siete:(id)sender;
- (IBAction)eight:(id)sender;//ocho:(id)sender;
- (IBAction)nine:(id)sender;//nueve:(id)sender;
- (IBAction)zero:(id)sender;//cero:(id)sender;
- (IBAction)cancel:(id)sender;//cancel:(id)sender;
-(void)checkCode;//verificarClave;

@end

BlockKeypadViewController.m で:

//
//  BlockKeypadViewController.m
//  Consultablet
//
//  Created by EDGARD AGUIRRE ROZO on 22/03/13.
//  Copyright (c) 2013 Colombia Creative Software. All rights reserved.
//

#import "BlockKeypadViewController.h"
@implementation UILabel (My2)
//- (void)setImage:(UIImage *)image forState:(UIControlState)state animated:(BOOL)animated
- (void)setHidden:(BOOL)hidden animated:(BOOL)animated
{
    //[self setImage:image forState:state];
    [self setHidden:hidden];
    if (animated)
    {
        CATransition *animation = [CATransition animation];
        [animation setType:kCATransitionFade];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setFillMode:kCAFillModeBoth];
        [animation setDuration:.3];
        [[self layer] addAnimation:animation forKey:@"UILabelSetAnimationKey"];
    }
}
- (void)setHidden:(BOOL)hidden animated:(BOOL)animated seconds:(int)seconds
{
    //[self setImage:image forState:state];
    [self setHidden:hidden];
    if (animated)
    {
        CATransition *animation = [CATransition animation];
        [animation setType:kCATransitionFade];
        [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
        [animation setFillMode:kCAFillModeBoth];
        [animation setDuration:seconds];
        [[self layer] addAnimation:animation forKey:@"UILabelSetAnimationKey"];
    }
}
@end
@interface BlockKeypadViewController ()

@end

@implementation BlockKeypadViewController
@synthesize digit1,digit2,digit3,digit4,counter,codeIn,unlockCode,wrongCodeLabel,tryAgainLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.counter = 1;
    self.codeIn=0;

    self.unlockCode=1234;
    NSLog(@"Unlock Code %d",self.unlockCode);

    [digit1 setHidden:YES animated:YES];
    [digit2 setHidden:YES animated:YES];
    [digit3 setHidden:YES animated:YES];
    [digit4 setHidden:YES animated:YES];
}
-(void)checkCode
{
    if(self.codeIn==self.unlockCode)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {
        [wrongCodeLabel setHidden:NO animated:YES seconds:.1];
        [tryAgainLabel setHidden:NO animated:YES seconds:.1];
        [self.digit1 setHidden:YES animated:YES];
        [self.digit2 setHidden:YES animated:YES];
        [self.digit3 setHidden:YES animated:YES];
        [self.digit4 setHidden:YES animated:YES];
        self.codeIn = 0;

        NSLog(@"Wrong Code");
    }
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
-(void) calculate:(int)number
{
    if(self.counter==1)
    {
        [wrongCodeLabel setHidden:YES animated:YES seconds:.2];
        [tryAgainLabel setHidden:YES animated:YES seconds:.2];
        [self.digit1 setHidden:NO animated:YES];
        self.codeIn = number*1000;
    }
    if(self.counter==2)
    {
        [self.digit2 setHidden:NO animated:YES];
        self.codeIn = self.codeIn+number*100;
    }
    if(self.counter==3)
    {
        [self.digit3 setHidden:NO animated:YES];
        self.codeIn = self.codeIn+number*10;
    }
    if(self.counter==4)
    {
        [self.digit4 setHidden:NO animated:YES];
        self.codeIn = self.codeIn+number;
        [self performSelector:@selector(checkCode) withObject:nil afterDelay:0.2];
    }
    if(self.counter<4)
    {
        self.counter++;
    }
    else
    {
        self.counter=1;
    }
}
- (IBAction)one:(id)sender
{
    [self calculate:1];
}
- (IBAction)two:(id)sender
{
    [self calculate:2];
}
- (IBAction)three:(id)sender
{
    [self calculate:3];
}
- (IBAction)four:(id)sender
{
    [self calculate:4];
}
- (IBAction)five:(id)sender
{
    [self calculate:5];
}
- (IBAction)six:(id)sender
{
   [self calculate:6];
}
- (IBAction)seven:(id)sender
{
    [self calculate:7];
}
- (IBAction)eight:(id)sender
{
    [self calculate:8];
}
- (IBAction)nine:(id)sender
{
    [self calculate:9];
}
- (IBAction)zero:(id)sender
{
    [self calculate:0];
}
- (IBAction)cancel:(id)sender
{
    [self.digit1 setHidden:YES animated:YES];
    [self.digit2 setHidden:YES animated:YES];
    [self.digit3 setHidden:YES animated:YES];
    [self.digit4 setHidden:YES animated:YES];
    self.codeIn = 0;
    self.counter = 1;
}


@end
于 2013-04-09T23:04:12.103 に答える
0

AppDelegateこれまたは任意のLockScreenソリューションを実装するために を使用する必要はありません (実際、このネズミイルカに使用することはお勧めしません) 。RootViewControllerからへのセグエを作成し、LockScreen必要に応じて名前を付ける必要があります (例: lockItSegue)。次に、ボタン アクション呼び出しから(ユーザーが正しいコードを入力したら) の[self performSegueWithIdentifier:@"lockItSegue" sender:self]; ロジック ( ) で呼び出します。BlockKeypadViewController.mLockScreen[self dismissViewControllerAnimated:YES completion:nil];

于 2013-04-13T16:21:16.427 に答える
0

appDelegate から HomeVC の上に lockVC を提示するには、次を使用します。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
HomeVC *hvc = [storyboard instantiateViewControllerWithIdentifier:@"HomeVC"];
self.window.rootViewController = hvc;
[self.window makeKeyAndVisible];

LockVC *lvc = [storyboard instantiateViewControllerWithIdentifier:@"LockVC"] 
[self.window.rootViewController presentViewController:lvc animated:YES completion:nil];
于 2013-01-29T20:21:39.587 に答える