滚动视图在按钮单击时向上和向下滚动

Vis*_*hal 3 iphone xcode uiscrollview ios ios6

可能重复:以
编程方式滚动UIScrollView

目前,我正在开发一个应用程序,我已经UIScrollView和一些按钮以编程方式插入scroll view.Scrolling这些添加按钮工作正常.但是我想再添加两个按钮并在一个按钮上单击scroll view scrolling到底部并显示最后一个底部

按钮,当我点击第二个按钮时,它滚动到顶部,它显示最顶部的按钮.我已经尝试了这么多,但不能成功.我怎么解决这个问题?提前致谢.

Man*_*ola 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];
Run Code Online (Sandbox Code Playgroud)

如果已知滚动大小,则我们可以设置按钮单击事件

-(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];
    }
}
Run Code Online (Sandbox Code Playgroud)