如何在iphone sdk中为视图添加自动滚动功能? [英] How to add auto scroll functionality to a view in iphone sdk?
问题描述
我是自动滚动功能的新手。我有一个非常冗长的.png文件。我想要做的是,当我点击一个按钮时,我想自动开始滚动该图像。我在sdk中浏览了scrollView示例代码。但我感到困惑。请任何人帮助我
I'm new to auto scroll functionality. I have a very lengthy .png file. what I want to do is, when I click a button I want to automatically start scrolling of that image. I had gone through scrollView sample code in sdk. but I get confused. Please any one help me
提前致谢
Praveena
Thanks in advance Praveena
推荐答案
滚动是通过设置内容偏移来实现的。
Scrolling is achieved by setting the content offset.
想象一个视图控制器构造类似这样的东西(例如在-viewDidLoad中):
Imagine a view controller constructed something like this (e.g. in -viewDidLoad):
// Load image.
UIImage *image = [UIImage imageNamed:@"image.png"];
// Create image view to hold the image.
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, [image size].width, [image size].height)];
[imageView setImage:image];
// Create a scroll view that is the size of the view.
scrollView = [[UIScrollView alloc] initWithFrame:[[self view] bounds]];
// Important: If the content size is less than the scroll view frame, then it will not scroll.
[scrollView setContentSize:[image size]];
// Add to view hierarchy.
[scrollView addSubview:imageView];
[[self view] addSubview:scrollView];
要使其滚动,只需执行以下操作:
To make it scroll, just do this:
[scrollView setContentOffset:CGPointMake(0, 100) animated:YES];
要使滚动连续,您需要设置更新内容偏移的计时器。
To have the scrolling to be continuous, you need to set up a timer that updates the content offset.
这篇关于如何在iphone sdk中为视图添加自动滚动功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!