私は次のように構築された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;
}
}
これが画像の詳細です。最初の画像の青い矢印は、部分的に非表示になっている左ボタンの以前の状態と、クリックするとスクロールビューの中央に移動することを示しています。
どうもありがとう