我有一个iphone应用程序,我在其中显示一系列图像。当用户点击图像时,我需要将该图像带到第一个位置,表明它是所选图像。我能够通过子类化在uiscrollview中实现挖掘。但是我无法将imageview定位到uiscrollview中的第一个。请帮助解决这个问题。 提前谢谢。
答案 0 :(得分:3)
您可以使用 contentOffset 属性将滚动视图移动到所需位置。您可以使用触摸位置计算图像位置。例如,如果图像水平滚动,
float _x = touchedX - (touchedX % imageViewWidth);
CGPoint contentOffset = CGPointMake(_x, 0); // to scroll horizontally
[scrollView setContentOffset:contentOffset animated:YES];
答案 1 :(得分:0)
如果您在scrollview中知道imageview的位置,那么您可以在UIScrollView中借助setContentOffset:animated:
在视图中显示它。
希望这会对你有所帮助。