您必須爲您的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)];
}
}
但我不想改變按鈕的框架......只需要改變滾動視圖的內容大小... – h999
現在我的更新檢查回答 – wesley
這裏什麼是識別器?我指的是哪一類的實例?你是如何得到它的? – h999