单击按钮滚动 UIScrollView

scrolling a UIScrollView on the click of a button(单击按钮滚动 UIScrollView)
本文介绍了单击按钮滚动 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)