作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ScrollView ,它必须显示大于可用显示区域的 View 。
我想轻松地设计用户界面,而无需每次必须进行一些更改时上下移动嵌入式 View 。
问题是可见区域之外的所有东西在 IB 中都是不可见的。
是否有任何开关或技巧可以使 IB 中的所有内容都可见?
最佳答案
更新
我已发布 another solution here我认为它更简单更好,并且适用于 Storyboard。
原来的
使用适当的 super View 、位置和大小在 Nib 中创建 ScrollView 。
接下来,创建一个完全独立的顶级 UIView
通过拖动 UIView
的实例将其拖放到任何现有 View 之外的工作区中。在属性检查器中,将大小弹出窗口设置为“无”,并确保状态栏、顶部栏和底部栏都设置为无。下面是一个例子:
这个新的顶级 View 将是您的内容 View 。给你的 View Controller 两个导出:scrollView
和 contentView
:
@interface MyViewController
@property (nonatomic, weak) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) IBOutlet UIView *contentView;
@end
scrollView
导出到 ScrollView 并连接
contentView
导出到内容 View 。
viewDidLoad
中, 添加
contentView
作为
scrollView
的 subview 并设置
scrollView.contentSize
到
contentView
的大小:
@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/
我是一名优秀的程序员,十分优秀!