我有一个UIView。在此视图中,我添加了 UIScrollView.和包含 UIButton 的滚动视图。一切都以编程方式创建。最初,滚动视图的内容大小与视图大小相同。用户可以将按钮拖到里面。现在,如果按钮到达角落或滚动视图的任何一侧。如果将其拖动到那里超过 1 秒,则滚动视图的内容大小应该在该侧增加。我对这种技术或使用哪种方法一无所知,我们可以得到它。请帮助我。任何提示将不胜感激。谢谢你。
您必须为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)];
}
}