2016-10-13 8 views
0

私のプロジェクトはUIButtonsで、コードブロックを実行するのに1秒かかります。ALL UIButtonの遅延実行ブロック

私は他のプロジェクトのボタンが正常に動作していますが、何らかの理由でこのプロジェクトには迷惑をかけることがあります。

ボタンは、彼らはすぐに押される必要があるので、dailer番号です:1の 相続人例:ここでは

- (IBAction)phonePressed:(id)sender { 
    UITapGestureRecognizer *backspaceGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(backspace)]; 
    UIButton *one = [[UIButton alloc] initWithFrame:CGRectMake(menuShadowLayer2.frame.origin.x+10, menuShadowLayer2.frame.origin.y+10, 80, 80)]; 
    one.layer.cornerRadius = 40; 
    one.layer.borderColor = [UIColor lightGrayColor].CGColor; 
    one.layer.borderWidth = 1; 
    [one setBackgroundColor:[UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:0.3]]; 
    [one setTitle:@"1" forState:UIControlStateNormal]; 
    [one.titleLabel setTextAlignment:NSTextAlignmentCenter]; 
    [one setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal]; 
    [one.titleLabel setFont:[UIFont fontWithName:@"STHeitiSC-Light" size:50]]; 
    [container addSubview:one]; 
    [one addGestureRecognizer:tap1]; 
... 

- (void)dailed1 { 
    numberDailed.text = [numberDailed.text stringByAppendingString:@"1"]; 
    NSLog(@"1"); 
} 

は遅くない場合は、同じように遅いですUIControlEventTouchUpInsideを使用して、別のボタンです。

UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(numberDailed.frame.origin.x, numberDailed.frame.origin.y+200, numberDailed.frame.size.width+40, 110)]; 
    cancel.layer.cornerRadius = 15; 
    [cancel setImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal]; 
    cancel.clipsToBounds = YES; 
    [container addSubview:cancel]; 
    [cancel addTarget:self 
      action:@selector(clearNumber:) 
    forControlEvents:UIControlEventTouchDown]; 
... 

-(IBAction)clearNumber:(id)sender{ 
    [numberDailed setText:@""]; 
} 

私はボタンUIControlEventTouchUpInsideまたはTouchDownさえも遅かったの使用などUITapGestureRecognizerを使用していました。

このボタン(one)を押すと、もう一度タップするまでに0.5秒ほど待たなければなりません。これは明らかに数字の半分と半分を入力することが文字列に追加されていないときに欲求不満を引き起こします。

UIScrollViewdelaysContentTouches = NO; に設定しました。ボタンがすぐにハイライト表示されます。すぐにコードを実行することはありません。 ボタンoneを例として使用しましたが、これは私のプロジェクトのALL UIButtonsに適用されます。 考えますか?あなたがジェスチャーを使用している

+1

なぜ「UIButton」でタップジェスチャーを使用していますか? 'UIButton'はタップの処理をサポートしています。 – rmaddy

+0

ボタンにタップジェスチャーが付いているのはなぜですか?既にタップジェスチャーがあるので、ボタンにはタップジェスチャーを追加しないでください。あなたはUIControlEventTouchUpInsideを使うべきです、なぜそれがより遅いのですか?詳細を追加してください。 –

+0

@rmaddy私は通常、UIControlEventTouchUpInsideを使用しますが、投稿に記載されているように、私のタップジェスチャーよりもさらに遅いです。 – Manesh

答えて

0

問題は、これがすべてをスピードアップ取り除く、私のプロジェクトに(推奨されません)MapBox APIであることが判明。すべてのコードはうまくいき、実行セレクタに戻ってジェスチャを削除しました。

0

、代わりに

[one addGestureRecognizer:tap1]; 

、あなたはボタンアクションに

[one addTarget:self action: @selector(dailed1:)]; 
0

カップルの事を使用する必要があります。他の人が指摘したように、あなたはどんなジェスチャーを必要としませんが、ボタンにアクション/ターゲットを添付する必要があり、第二に

UIButton *numberButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
numberButton.frame = CGRectMake(...); 

[numberButton addTarget:self action:@selector(numberDialled:) forControlEvents: UIControlEventTouchUpInside]; 

第三に、まず、そのようなあなたのボタンを作成しますあなたのIBActionを作成します。

- (IBAction) numberDialled:(id)sender 
関連する問題