UIScrollView 实现 [英] UIScrollView Implementation

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

问题描述

使用 Storyboards,我有一个 UITabBarController,里面有一个 UIScrollView,在 scrollView 里面有一个 UIView.我的视图非常大,并不完全适合故事板.我无法一直滚动到视图的底部.

Using Storyboards, I have a UITabBarController with a UIScrollView inside, with a UIView inside the scrollView. My view is very large, and does not completely fit in the storyboard. I am not able to scroll all the way to the bottom of the View.

如果你从头开始构建所有这些,你会怎么做?

If you was building all of this from scratch, how would you go about it?

推荐答案

假设您有一个带有 2 个视图的 UITabBarController.因此你有两个视图控制器.让我们称它们为A"和B".如果您参考此 链接.您也可以使用 Storyboard 来实现这一点.

Say you have a UITabBarController with 2 views. hence you have two View Controllers. Lets call them 'A' and 'B'. Configuring two views within a tab bar controller shouldn't be too difficult if you refer to this link. You can achieve this using Storyboard too.

现在说,在视图A"中,您希望在 UIScrollView 中使用 UIView.您要做的是声明一个 UIScrollView ,其框架大小等于屏幕的尺寸,但将 contentSize 设置为您想要的大尺寸.您现在可以在此滚动视图中拥有大视图.

Now say, in view 'A' you want your large UIView within the UIScrollView. What you do is declare a UIScrollView with a framesize that is equal to the screen's dimensions but set the contentSize to your large size that you wanted. You can now have you large view within this scroll view.

示例:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 520)]; // little less than 568 to accommodate the tabBar
[scrollView setContentSize:CGSizeMake(320, 1500)];
UIView *largeView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 320, 100)];
[scrollView addSubview:largeView];
[self.view addSubview:scrollView];

您也可以在 Storyboard 中执行上述操作,但我更喜欢将代码用于此类任务.希望有所帮助.如果您需要更多帮助,请告诉我.

You can do the above in Storyboard as well but i prefer using code for such tasks. Hope that helped. Let me know if you need more help.

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

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