我正在努力解决在滚动视图中尝试平移的问题。我已经创建了一段测试代码(下面)来解决问题(这就是为什么它看起来很奇怪 - 原谅我)。
快速摘要:
我在scrollView中有一系列EasyTableView水平滚动条。我已经设置了一个双指锅识别器来启动平移。垂直滚动工作得很好,滚动条内的水平滚动工作正常,检测到两个手指平移手势并调用委托方法。但是,滚动条不会在屏幕上翻译。
我注意到原点x和原点y始终为零,即使卷轴的初始位置绝对不是 - (下面的输出)。
显然,我有一个参考框架问题,但我不能为我的生活弄明白。代码:
@synthesize panRecognizer, horizontalView;
- (void)viewDidLoad
{
[super viewDidLoad];
CGFloat yOffset = 0;
CGRect fullScreenRect=[[UIScreen mainScreen] applicationFrame];
UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:fullScreenRect];
EasyTableView *ehorizontalView;
self.view=scrollView;
for(int i=0; i<5; i++){
UIPanGestureRecognizer *twoFingerPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panDetected:)];
twoFingerPan.minimumNumberOfTouches = 2;
twoFingerPan.maximumNumberOfTouches = 2;
CGRect frameRect = CGRectMake(0, yOffset, PORTRAIT_WIDTH, HORIZONTAL_TABLEVIEW_HEIGHT); // do any further configuration to the scroll view
EasyTableView *view = [[EasyTableView alloc] initWithFrame:frameRect numberOfColumns:NUM_OF_CELLS ofWidth:VERTICAL_TABLEVIEW_WIDTH];
ehorizontalView = view;
// test code
if(i==1){
self.horizontalView=horizontalView;
self.panRecognizer=twoFingerPan;
}
ehorizontalView.delegate = self;
[ehorizontalView addGestureRecognizer:twoFingerPan];
ehorizontalView.tableView.backgroundColor = TABLE_BACKGROUND_COLOR;
ehorizontalView.tableView.allowsSelection = YES;
ehorizontalView.tableView.separatorColor = [UIColor colorWithRed: (CGFloat)0 green:(CGFloat)51/255 blue:(CGFloat)153/255 alpha:(CGFloat)0.3];
ehorizontalView.cellBackgroundColor = [UIColor colorWithRed:(CGFloat)0 green:(CGFloat)51/255 blue:(CGFloat)153/255 alpha:(CGFloat)0.3];
ehorizontalView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[ehorizontalView addGestureRecognizer:twoFingerPan];
[self.view addSubview:ehorizontalView];
yOffset+=180;
}
[scrollView setContentSize:CGSizeMake( 320, yOffset+460)];
}
- (void)panDetected:(UIPanGestureRecognizer *)pr
{
EasyTableView *v;
if(panRecognizer==pr){
NSLog(@"This works here - recognized: %f", [pr translationInView:self.view].y);
v=self.horizontalView;
CGPoint translation = [pr translationInView:self.view];
CGRect r=v.frame;
NSLog(@"Coordinates rx %f ry %f tx %f ty %f",r.origin.x,r.origin.y,translation.x,translation.y);
r.origin.y += translation.y;
r.origin.x=0;
[v setFrame:r];
[pr setTranslation:CGPointZero inView:self.view];
}
}
我也有一些来自panDetected的输出:
2012-05-04 08:43:48.317 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx 0.000000 ty 0.500000
2012-05-04 08:43:48.329 ScrollerTest[1920:707] This works here - recognized: 0.500000
2012-05-04 08:43:48.334 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx 0.000000 ty 0.500000
2012-05-04 08:43:48.358 ScrollerTest[1920:707] This works here - recognized: 0.500000
2012-05-04 08:43:48.365 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx 0.000000 ty 0.500000
2012-05-04 08:43:48.371 ScrollerTest[1920:707] This works here - recognized: 0.000000
2012-05-04 08:43:48.373 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx -0.500000 ty 0.000000
2012-05-04 08:43:48.550 ScrollerTest[1920:707] This works here - recognized: 0.000000
2012-05-04 08:43:48.554 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx -0.500000 ty 0.000000
2012-05-04 08:43:48.789 ScrollerTest[1920:707] This works here - recognized: 1.000000
2012-05-04 08:43:48.793 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx 0.000000 ty 1.000000
2012-05-04 08:43:48.805 ScrollerTest[1920:707] This works here - recognized: 0.000000
2012-05-04 08:43:48.809 ScrollerTest[1920:707] Coordinates rx 0.000000 ry 0.000000 tx 0.000000 ty 0.000000
非常感谢所提供的任何帮助!
谢谢。