0

私は次のように構築されたUIbuttonsのscrollviewのscrollviewを持っています:

-(void) loadCompeticionSlide{

    float x=0;

    for (int i = 0; i < [categoriasArray count]; i++) {

        NSDictionary *categoria = [categoriasArray objectAtIndex:i];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        NSString *titleString  = [categoria valueForKey:@"competicion"];  // get button title

        btn.titleLabel.font = [UIFont boldSystemFontOfSize:11.0];

        CGSize fontSize = [titleString sizeWithFont:[UIFont systemFontOfSize:11.0]];

        CGRect currentFrame = btn.frame;

        CGRect buttonFrame = CGRectMake(x, currentFrame.origin.y, fontSize.width + 22.0, fontSize.height + 12.0);

        [btn setFrame:buttonFrame];

        x = x + fontSize.width + 35.0;

        [btn setTitle:titleString forState: UIControlStateNormal];

        int idc = [[categoria valueForKey:@"idc"]intValue];

         [btn addTarget:self action:@selector(cambiarCompeticion:) forControlEvents:UIControlEventTouchUpInside];

         [btn setTag:idc];

        [self.competicionSlide addSubview:btn];

    }

    //[competicionSlide setBackgroundColor:[UIColor whiteColor]];
    competicionSlide.contentSize = CGSizeMake(350,35);
    competicionSlide.layer.cornerRadius = 11;
    competicionSlide.layer.masksToBounds = YES;

}

次に、追加されたセレクターcambiarCompeticion:で、ボタンをクリックしました。ここでは、scrollRectToVisible:を使用して、クリックしたUIButtonをそれを含むUIScrollviewの中央にスクロールさせる必要がありますが、その方法がわかりません。

これは、scrollRectToVisibleを呼び出す必要があることを理解しているボタン選択によってトリガーされるセレクターメソッドです。

-(void)cambiarCompeticion:(UIButton*)boton{

    int idCompeticion;

    idCompeticion = boton.tag;

    switch (idCompeticion) {
        case 1:
            [self tablaLigaRegular];
            break;

        case 5:
            [self tablaCoparey];
            break;

        case 10:
            [self tablaPlayOff];
            break;    

           }


}

これが画像の詳細です。最初の画像の青い矢印は、部分的に非表示になっている左ボタンの以前の状態と、クリックするとスクロールビューの中央に移動することを示しています。

ここに画像の説明を入力してください

どうもありがとう

4

1 に答える 1

1

ボトンパラメーター(cambiarCompeticion:セレクターから)は、必要なものがすべて含まれています。このように呼び出すだけです(「competicionSlide」がUIScrollViewであると仮定します):

[self.competicionSlide scrollRectToVisible:boton.frame];

幸運を !

于 2012-05-21T16:35:00.023 に答える