Note that there are some explanatory texts on larger screens.

plurals
  1. POPanning within a ScrollView
    primarykey
    data
    text
    <p>I am struggling with the problem of trying to pan within a scrollview. I have created a piece of test code (below) to exercise the problem (which is why it looks so strange - forgive me).</p> <p>A quick summary:</p> <p>I have a series of EasyTableView horizontal scrollers in a scrollView. I have set up a two-fingered pan recognizer to initiate the pan. vertical scrolling works just fine, horizontal scrolling within the scrollers works just fine, and the two fingered pan gesture is detected and the delegate method is called. However, the scroller will not translate on the screen.</p> <p>I note the origin x and origin y are always zero, even though the initial position of the scroller is definitely not that - (output below).</p> <p>obviously, I have a frame of reference problem, but I cannot for the life of me figure it out.</p> <p>Code:</p> <pre><code>@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&lt;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]; } </code></pre> <p>}</p> <p>I also have some output from panDetected:</p> <pre><code>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 </code></pre> <p>Any help provided with be most gratefully received!</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload