以编程方式控制UIScrollView [英] Programatically Control UIScrollView

查看:90
本文介绍了以编程方式控制UIScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有以编程方式控制UIScrollView的方法?就像在,获取其位置的值,沿着它滚动多远的东西并改变它的位置,以编程方式滚动它?

Is there a method of programatically controlling a UIScrollView? As in, getting a value for its location, so how far along it is scrolled and things and change its position, scroll it programatically?

希望你能提供帮助,谢谢。

Hope you can help, thanks.

推荐答案

我不知道@Alexandergre或@JAgostoni正在谈论什么。滚动UIScrollView非常简单。

I don't know what either of @Alexandergre or @JAgostoni are talking about. Scrolling in UIScrollView is really easy.

我建议您查看UIScrollView的文档:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class /Reference/UIScrollView.html

I suggest you take a look at the documentation for UIScrollView: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html

要滚动UIScrollView,只需使用

To scroll a UIScrollView, simply use

- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

示例:

Example:

[myScrollView scrollRectToVisible:CGRectMake(20, 20, 320, 480) animated:YES];

这会将带动画的UIScrollView滚动到x轴上的20,y上的20和320x480高度和宽度。

That will scroll a UIScrollView with animation to a 20 on the x axis, 20 on the y and 320x480 height and width.

如果你想获取它自己的视图信息(例如哪个框架是可见的)你应该使用UIView中的方法和属性,因为它是UIScrollView的家长。
查看UIView文档: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

If you want to get information of the view it self(for example what frame is visible) you should use methods and properties from UIView, as it's UIScrollView's parent. Check out the UIView documentation at: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

要获得可见的框架,使用

To get the frame that is visible, use

myScrollView.frame;

请勿将其与内容大小混合

Do not mix it up with the content size

myScrollView.contentSize;

但是,正如我所说。 使用文档!

But, as i said. Use the documentation!

这篇关于以编程方式控制UIScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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