2013-03-13 66 views

回答

0

首先您的視圖中添加滾動視圖和in.h中文件寫入委託<UIGestureRecognizerDelegate,UIScrollViewDelegate>

在您的viewDidLoad寫

UITapGestureRecognizer *singleFingerTap = 
    [[UITapGestureRecognizer alloc] initWithTarget:self 
              action:@selector(handleSingleTap:)]; 
    [self.view addGestureRecognizer:singleFingerTap]; 
    [singleFingerTap release]; 

    scrl.scrollEnabled = YES; // scrl is my UIScrollView 
    scrl.delegate = self; 
    scrl.contentSize=CGSizeMake(320, 680); 
    [self.view addSubview:scrl]; 

而且在handleSingleTap方法編寫代碼。它也會滾動,如果你點擊視圖,handleSingleTap方法將被調用。

+0

謝謝我會試試 – user2159978 2013-03-13 11:53:32

0

我在製作UIScrollView覆蓋SpriteKit視圖時遇到了類似的問題,因此用戶可以滾動大型遊戲菜單。滾動視圖'竊取'所有的水龍頭,我不能在滾動視圖後面按按鈕,就像我的'後退按鈕'。我在滾動視圖中也有按鈕,我在我的原始精靈套件場景中擁有處理程序 - 並且厭惡進入我的可滾動視圖。

因此,我通過簡單地將所有的觸摸事件發送給超類和超視圖來解決這個問題。 我不確定是否有任何大的缺點,但我現在得到觸摸和滾動。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self.superview touchesBegan:touches withEvent:event]; 
    [super touchesBegan:touches withEvent:event]; 
} 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self.superview touchesMoved:touches withEvent:event]; 
    [super touchesMoved:touches withEvent:event]; 
} 

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self.superview touchesCancelled:touches withEvent:event]; 
    [super touchesCancelled:touches withEvent:event]; 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [self.superview touchesEnded:touches withEvent:event]; 
    [super touchesEnded:touches withEvent:event]; 
}