1
有幾個帖子與此類似,但我無法將其他響應修改爲我的代碼。我在使用我的scrollview
中的方法touchesBegan
,touchesMoved
和touchesEnded
時遇到問題。在UIScrollView中觸摸交互
我目前有一個大的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的子類,但是這沒有帶給我喜悅。
我真的不理解這個添加到您的滾動視圖。當然,UITapGestureRecognizer只能檢測單點觸摸事件?我需要能夠跟蹤觸摸動作。 –
在這種情況下,您需要將該手勢也添加到您的滾動視圖 –
我已經嘗試使用此方法。問題在於UITapGestureRecognizer在觸地事件後無法檢測到移動 - 它的行爲與touchesBegan相似。我需要像touchesMoved那樣的東西。 –