1

スクロールビュー内でパンしようとする問題に苦労しています。私は問題を実行するためにテストコード(以下)を作成しました(それがとても奇妙に見える理由です-許してください)。

簡単な要約:

scrollViewに一連のEasyTableView水平スクローラーがあります。パンを開始するために2本指のパンレコグナイザーを設定しました。垂直スクロールは問題なく機能し、スクローラー内の水平スクロールは問題なく機能し、2本の指によるパンジェスチャが検出され、デリゲートメソッドが呼び出されます。ただし、スクローラーは画面上で翻訳されません。

スクローラーの初期位置は間違いなく-(以下の出力)ではありませんが、原点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

提供されたどんな助けも最も感謝して受け取られます!

ありがとうございました。

4

0 に答える 0