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

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

问题描述

是否存在以编程方式控制UIScrollView的方法?像这样,获取其位置的值,那么沿着它滚动到多远,物体又改变它的位置,以编程方式滚动它?

Is there a method of programmatically 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 programmatically?

推荐答案

我不知道@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/库/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天全站免登陆