单击按钮滚动UIScrollView [英] scrolling a UIScrollView on the click of a button

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

问题描述

我想知道是否可以通过单击UIButton来滚动UIScrollView,如果可以,有人可以告诉我该怎么做.

I would like to know if it is possible for me to scroll a UIScrollView on the click of a UIButton and if so, would someone be able to tell me how to.

当前,我正在使用以下代码查看在滚动视图中左侧是否有更多内容,如果存在,请显示一个图像,该图像告诉用户如果他们向左滚动则有更多内容. 我想实现一种功能,在其中添加UIButton而不是图像,并且当左侧有更多内容可用时,并且当用户单击按钮时,滚动视图将滚动到其左侧.

currently I am using the below code to see if in the scrollview more content is there to its left and if it is there, display an image which would tell the users that there is more content if they scroll to the left. I would like to implement a functionality where I add a UIButton instead of the image and when more content is available on the left and when the user clicks the button, the scrollview would scroll to its left.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView1 {
    if (scrollView1.contentOffset.x == scrollView1.contentSize.width - scrollView1.frame.size.width) 
    {        
        // reached the right
        self.imageView.hidden = YES;
    }

    else
    {
        self.imageView.hidden = NO;
    }
}

如果有人可以帮我解决这个问题,那就太好了.

It would be great if someone could help me out on this.

推荐答案

我认为这很容易.使用:

That's pretty easy, I think. Use:

[scrollView1 setContentOffset:CGPointMake(x, 0) animated:YES];

其中X是scrollView1.contentOffset.x + scrollView1.contentSize.width的值.

Where X is the value of scrollView1.contentOffset.x + scrollView1.contentSize.width.

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

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