滚动视图向上滚动按下按钮单击 [英] Scroll view scrolling up & down on button click

查看:48
本文介绍了滚动视图向上滚动按下按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Possible Duplicate:
Programmatically scroll a UIScrollView

当前,我正在开发一个具有UIScrollView的应用程序,并且在scroll view.Scrolling中以编程方式插入了一些按钮,这些添加的按钮对我来说很好用.但我想加两个 更多按钮和在一个按钮上单击scroll view scrolling到底部,然后显示底部的最后一个

Currently, I am developing an App in which I have UIScrollView and some buttons are programatically inserted in scroll view.Scrolling of these added buttons work fine for me. but I want to add two more button & on one button click scroll view scrolling to bottom side and display bottom last

按钮,当我单击第二个按钮时,它会滚动到顶部,并显示最上面的按钮.我已经做了很多尝试,但是没有成功.我该如何解决?预先感谢.

buttons and when I click on second button it scroll to top side and it show top most button. I have tried so much but can't succeeded. How can I solve this? Thanks in advance.

推荐答案

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];

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

If Scroll Size is known then we can set the button click event

-(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];
    }
}

这篇关于滚动视图向上滚动按下按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆