单击按钮滚动 UIScrollView

2023-07-30移动开发问题
13

本文介绍了单击按钮滚动 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9

如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)...
2024-08-12 移动开发问题
13