[英]How to control scrolling in grid type view
UPDATED I have a grid ( SubViewGrid
) that I have drawn on a UIView
. 更新我有一个在
UIView
上绘制的网格( SubViewGrid
)。 I need to be able to prevent the far left column (time) from scrolling horizontally, and the top row (staff name) from scrolling vertically. 我需要能够防止最左边的列(时间)水平滚动,而最上面的列(员工名称)垂直滚动。
The data is drawn in SubViewData
, which is within the UIScrollView
. 数据绘制在
UIScrollView
内的SubViewData
。 I would imagine that I would need two (2) UIScrollView
s here, one for the SubViewGrid
, the other for the SubViewData
. 我想我在这里需要两(2)个
UIScrollView
,一个用于SubViewGrid
,另一个用于SubViewData
。 Question is: how to sync them to accomplish the user's needs? 问题是:如何同步它们以满足用户的需求?
UPDATE Here is the REVISED structure: 更新这里是REVISED结构:
@property (nonatomic, weak) IBOutlet UIScrollView *schedScrollView;
@property (nonatomic, weak) IBOutlet UIView * topGridView;
@property (nonatomic, weak) IBOutlet UIView * leftGridView;
@property (nonatomic, weak) IBOutlet UIView * topLeftView; // TODO
See this answer to a similar question . 看到类似问题的 答案 。
I think that's how you would need to approach this problem, with the fixed heading(s) in a separate subview to the data. 我认为这是解决此问题的方法,将固定标题放在数据的单独子视图中。 Then set the frame of the fixed subview in
scrollViewDidScroll:
to create the appearance of a fixed heading at the top (or side) of the scroll view. 然后在
scrollViewDidScroll:
设置固定子视图的框架,以在滚动视图的顶部(或侧面)创建固定标题的外观。
For example: Set the initial frame of the header subview to (0, 0, width, height)
, and then in scrollViewDidScroll:
set the frame to (0, contentOffset.y, width, height)
. 例如:将标题子视图的初始帧设置为
(0, 0, width, height)
,然后在scrollViewDidScroll:
将帧设置为(0, contentOffset.y, width, height)
。
EDIT: Here's an example. 编辑:这是一个例子。 In the below screenshot I set up the top row (people), left column (time), and top left cell (to hide the overlapping of the headers) inside a
UIScrollView
. 在下面的屏幕快照中,我在
UIScrollView
内设置了顶行(人),左列(时间)和左上单元(以隐藏标题的重叠)。 Then in scrollViewDidScroll:
I set the frames of the subviews to fix them to the top, left, and top-left respectively. 然后在
scrollViewDidScroll:
设置子视图的框架以分别将它们固定在顶部,左侧和左上角。
ViewController.h: ViewController.h:
@interface ViewController : UIViewController <UIScrollViewDelegate>
@property (nonatomic, weak) IBOutlet UIScrollView * theScrollView;
@property (nonatomic, weak) IBOutlet UIImageView * topView;
@property (nonatomic, weak) IBOutlet UIImageView * leftView;
@property (nonatomic, weak) IBOutlet UIView * topLeftView;
@end
ViewController.m: ViewController.m:
#import "ViewController.h"
@implementation ViewController
@synthesize theScrollView, topView, leftView, topLeftView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.theScrollView.delegate = self;
}
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
self.theScrollView.contentSize = CGSizeMake(502, 401);
}
#pragma mark UIScrollViewDelegate methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect tempFrame = self.topView.frame;
tempFrame.origin.y = scrollView.contentOffset.y;
self.topView.frame = tempFrame;
tempFrame = self.leftView.frame;
tempFrame.origin.x = scrollView.contentOffset.x;
self.leftView.frame = tempFrame;
tempFrame = self.topLeftView.frame;
tempFrame.origin.x = scrollView.contentOffset.x;
tempFrame.origin.y = scrollView.contentOffset.y;
self.topLeftView.frame = tempFrame;
}
@end
And that's all there is to it! 这就是全部! Hopefully this helps you.
希望这对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.