2014-05-05 76 views
0

我有2個UIWebView控件。使用這2個網頁瀏覽,我已成功實施滑動手勢動畫。的iOS:網頁視圖掃掠姿態

但問題是,當我點擊下一個或前一個按鈕(哦,是的,我也有一個,前,第一和最後一個按鈕來讀一本書),刷卡完美的作品。

但上的WebView它工作古怪。出現以下情況:

  • 刷卡不上的WebView工作。
  • 當我一個或下一個按鈕,按一下,然後輕掃的WebView上的WebView刷卡有效。

以下是我的代碼片段:

在viewDidLoad中:

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)]; 
[swipeRight setDirection:UISwipeGestureRecognizerDirectionLeft]; 
[webViewPage addGestureRecognizer:swipeRight]; 
[_webview2 addGestureRecognizer:swipeRight]; 


UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)]; 
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionRight]; 
[webViewPage addGestureRecognizer:swipeLeft]; 
[_webview2 addGestureRecognizer:swipeLeft]; 

要在UIWebView的啓用刷卡:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 
// NSLog(@"shouldRecognizeSimultaneouslyWithGestureRecognizer"); 
    return YES; 
} 



- (IBAction)btnPrevious_click:(id)sender { 
    //some code 

} 

- (IBAction)btnNext_click:(id)sender { 
    //some code 
} 

當我收到錯了嗎?

回答

1

從你的代碼,你必須添加2 UISwipeGestureRecognizer只在一個UIWebView名字是_webview2請更換按您的要求。

+1

嘿感謝它的工作。 1 upvote。另外讓我知道爲什麼我不得不添加單獨的gestureRecognizers到不同的webViews來執行相同的操作? – z22

0

像iPatel提及。每個webview都應該有自己的GestureRecognizers。所以,你應該總共有4個GestureRecognizers。

試試這個: -

UISwipeGestureRecognizer *swipeRight1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)]; 
[swipeRight1 setDirection:UISwipeGestureRecognizerDirectionLeft]; 
UISwipeGestureRecognizer *swipeLeft1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)]; 
[swipeLeft1 setDirection:UISwipeGestureRecognizerDirectionRight]; 
[_webview1 addGestureRecognizer:swipeRight1]; 
[_webview1 addGestureRecognizer:swipeLeft1]; 

UISwipeGestureRecognizer *swipeRight2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)]; 
[swipeRight2 setDirection:UISwipeGestureRecognizerDirectionLeft]; 
UISwipeGestureRecognizer *swipeLeft2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)]; 
[swipeLeft2 setDirection:UISwipeGestureRecognizerDirectionRight]; 
[_webview2 addGestureRecognizer:swipeRight2]; 
[_webview2 addGestureRecognizer:swipeLeft2];