我有带标签的UIScrollView。我正在获取触摸事件坐标。当用户在屏幕上单击时,我将单击坐标存储在变量中,然后我想以某种方式滚动视图(使用[myScrollView setContentOffset]之类的方法),以便使被单击点的y坐标成为我视图的中心,因此当您单击某些文本时,它将自动滚动到屏幕中心。我不确定如何锻炼这个数学...

任何帮助,高度赞赏!

最佳答案

UIScrollView *aScrollView;
CGPoint touchPoint;
[aScrollView scrollRectToVisible:CGRectMake(touchPoint.x - roundf(aScrollView.frame.size.width/2.),
                                                  touchPoint.y - roundf(aScrollView.frame.size.height/2.),
                                                  aScrollView.frame.size.width,
                                                  aScrollView.frame.size.height)
                                                  animated:YES];


应该管用。

10-06 13:54
查看更多