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

查看:18
本文介绍了单击按钮滚动 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天全站免登陆