3

重複の可能性:
UIScrollView をプログラムでスクロールする

現在、私が持っているアプリを開発しておりUIScrollView、いくつかのボタンがプログラムで挿入されscroll view.Scrolling、これらの追加されたボタンが正常に機能します。しかし、さらに2つのボタンを追加し、1つのボタンをクリックscroll view scrollingして下側にクリックし、最後に下を表示したい

ボタンと 2 番目のボタンをクリックすると、上部にスクロールし、一番上のボタンが表示されます。私は多くのことを試みましたが、成功することはできません。どうすればこれを解決できますか? 前もって感謝します。

4

3 に答える 3

7
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 20, 320, 400)];
scrollView.backgroundColor=[UIColor lightGrayColor];
scrollView.contentSize=CGSizeMake(320, 500);
scrollView.showsVerticalScrollIndicator=YES;
[self.view addSubview:scrollView];

スクロール サイズがわかっている場合は、ボタン クリック イベントを設定できます。

-(void)buttonCkicked:(UIButton*)sender
{
    if (sender.tag==1001) {
        [scrollView setContentOffset:CGPointMake(0, 100) animated:YES];
    }
    if (sender.tag==1002) {
        [scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    }
}
于 2012-11-07T10:10:27.030 に答える
3

これはあなたのpbmを解決するかもしれません

-(IBAction) clickfirstbutton 
{
   [scrollview setContentOffset:CGPointMake(0, (intvalue to the positon of two buttons)) animated:TRUE];
}

-(IBAction) clicksecondbutton
{
   [scrollview setContentOffset:CGPointMake(0, 0) animated:TRUE];
}
于 2012-11-07T09:08:24.087 に答える
2
-(IBAction)btn1_Clicked:(id)sender{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    yourScrollView.frame=CGRectMake(0, -scrollView.contentSize.height + 360, 320, scrollView.contentSize.height);/// set y (starting point) with your scrollview height
    [UIView commitAnimations];
}

-(IBAction)btn2_Clicked:(id)sender{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    yourScrollView.frame=CGRectMake(0,0 , 320, scrollView.contentSize.height);
    [UIView commitAnimations];
}
于 2012-11-07T09:19:48.193 に答える