-1

私は1つのUIViewを持っています。このビュー内に、UIScrollView を追加しました。1 つの UIButton を含むスクロールビューを追加しました。すべてがプログラムによって作成されます。最初はスクロールビューのコンテンツ サイズはビュー サイズと同じです。スクロールビューのコンテンツサイズよりも1秒以上ドラッグすると、その側でスクロールビューのコンテンツサイズが大きくなるはずです。あなた。

4

1 に答える 1

0

UIButton に UIPangesture 認識機能を追加する必要があります。パスチャー レコグナイザーのハンドルは、UIButton フレームと UIScrollview フレームを変更する必要があります。このイニシアチブの例を参考にしてください。

 UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
 [myButton setUserInteractionEnabled:YES];
 [myButton addGestureRecognizer:panGesture];

そして、ハンドルメソッドは次のようにする必要があります。

    -(IBAction)handlePanGesture:(UIPanGestureRecognizer *)sender
    {
     CGPoint translation = [sender translationInView:self.view];
     sender.view.center = CGPointMake(sender.view.center.x + translation.x, 
                                         sender.view.center.y + translation.y);
    [sender setTranslation:CGPointMake(0, 0) inView:self.view];

     //And check  sender x,y position with your `scrollview`,if it is crossed then you have to reset the `contentOffset`
     // Do the calculation like this
    if([sender.view.center].x>yourScrollviewXposition)
    {
  coordforX=([sender.view.center].x + translation.x);
  coordforY=([sender.view.center].y + translation.y);
//based on your calculated x, y position you have to calculate scrollview width and height
  [yourScrollView setContentSize:CGSizeMake(width,height)];
   }
 }
于 2013-10-10T09:18:07.777 に答える