有一些与此类似的帖子,但我无法将其他响应调整为我的代码。我在我touchesBegan
的.touchesMoved
touchesEnded
scrollview
我目前有一个大的scrollview
(3072 x 2304)。我有一个UIImageView
这样subview
的并希望检测到任何一个的触摸(没关系,因为它会为我产生相同的结果)。
这是我目前的处理方法:
//Set scrollview to size of image
self.myScrollView.contentSize = CGSizeMake(3072, 2304);
//Load image in big rect
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 3072, 2304)];
//set image to pic in bundle
myImageView.image = [UIImage imageNamed:@"dot.jpg"];
//make imageview subview of scrollview
[self.myScrollView addSubview: myImageView];
//Making subview for touches
CGRect frame = CGRectMake(0, 0, 3072, 2304);
touchView = [[UIScrollView alloc] initWithFrame:frame];
[self.myScrollView addSubview: touchView];
//Allow for 2 touches to move screen
for (UIGestureRecognizer *gestureRecognizer in myScrollView.gestureRecognizers)
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]])
{
UIPanGestureRecognizer *panGR = (UIPanGestureRecognizer *) gestureRecognizer;
panGR.minimumNumberOfTouches = 2;
}
}
笔记:
建议使用手势识别器的方法并不理想。我知道,别无选择touchesMoved
;实现这一点的唯一可行方法是子类化 UIScrollView,但这并没有给我带来任何乐趣。