gpt4 book ai didi

xcode - 如何在nib中轻松设计UIScrollView的内容

转载 作者:行者123 更新时间:2023-12-04 02:44:07 25 4
gpt4 key购买 nike

我有一个 ScrollView ,它必须显示大于可用显示区域的 View 。
我想轻松地设计用户界面,而无需每次必须进行一些更改时上下移动嵌入式 View 。
问题是可见区域之外的所有东西在 IB 中都是不可见的。

是否有任何开关或技巧可以使 IB 中的所有内容都可见?

最佳答案

更新

我已发布 another solution here我认为它更简单更好,并且适用于 Storyboard。

原来的

使用适当的 super View 、位置和大小在 Nib 中创建 ScrollView 。

接下来,创建一个完全独立的顶级 UIView通过拖动 UIView 的实例将其拖放到任何现有 View 之外的工作区中。在属性检查器中,将大小弹出窗口设置为“无”,并确保状态栏、顶部栏和底部栏都设置为无。下面是一个例子:

setting up content view

这个新的顶级 View 将是您的内容 View 。给你的 View Controller 两个导出:scrollViewcontentView :

@interface MyViewController

@property (nonatomic, weak) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) IBOutlet UIView *contentView;

@end

在 Nib 中,连接 scrollView导出到 ScrollView 并连接 contentView导出到内容 View 。

在内容 View 中构建您的内容 View 层次结构。根据需要将其大小设置为大 - 它可以大于 320x480(只要您将其所有条设置为无)。

在您的 View Controller 的 viewDidLoad 中, 添加 contentView作为 scrollView 的 subview 并设置 scrollView.contentSizecontentView 的大小:
@implementation MyViewController

@synthesize scrollView = _scrollView;
@synthesize contentView = _contentView;

- (void)viewDidLoad {
[super viewDidLoad];
[self configureScrollView];
}

- (void)configureScrollView {
CGSize size = self.contentView.bounds.size;
self.contentView.frame = CGRectMake(0, 0, size.width, size.height);
[self.scrollView addSubview:self.contentView];
self.scrollView.contentSize = size;

// If you don't use self.contentView anywhere else, clear it here.
self.contentView = nil;
// If you use it elsewhere, clear it in `dealloc` and `viewDidUnload`.
}

关于xcode - 如何在nib中轻松设计UIScrollView的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9987436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com