6

के साथ UIPanGestureRecognizer संघर्ष मैं स्क्रॉलव्यू युक्त दृश्य में पैन इशारा पहचानकर्ता जोड़ने की कोशिश कर रहा हूं, लेकिन मुझे लगता है कि मुझे प्राथमिकताओं के साथ समस्याएं हैं।स्क्रॉलव्यू

मेरे वैश्विक UIView एक UIPanGestureRecognizer इस तरह सेट है:

_bottomPanGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(bottomPanGestureDetected:)]; 
_bottomPanGestureRecognizer.minimumNumberOfTouches = 2; 
_bottomPanGestureRecognizer.maximumNumberOfTouches = 2; 
_bottomPanGestureRecognizer.delaysTouchesBegan = NO; 
_bottomPanGestureRecognizer.delaysTouchesEnded = NO; 

मैं चुटकी किसी प्रकार के साथ नीचे से एक और दृश्य प्रदर्शित करने के लिए इस कदम को पहचान करना चाहते हैं नीचे करने के लिए ऊपर।

समस्या यह है कि स्क्रॉलव्यू मेरे सामने अपने पैन इशारे को पहचान रहा है।

तो मैं यह धन्यवाद करने के लिए देरी करने की कोशिश की:

[_scrollView.panGestureRecognizer requireGestureRecognizerToFail:_bottomPanGestureRecognizer]; 

और यह काम कर रहा है, scrollview घटना अप पहचानकर्ता के लिए नीचे मेरी दो उंगली के बाद निकाल दिया जाता है, लेकिन समस्या यह है जब मैं केवल करने के लिए एक अंगुली का उपयोग स्क्रॉलव्यू में स्क्रॉल करें, स्क्रॉल एक छोटी देरी के बाद काम करता है।

मुझे इस कार्यक्रम के लिए कोई देरी नहीं है, क्या यह संभव है? किसी भी विचार का स्वागत किया!

चीयर्स।

सिरिल

+0

जानते हैं कि आपको 'maximumNumberOfTouches' की' _scrollView.panGestureRecognizer' को '1' स्थापित करने के लिए कोशिश की है? – kovpas

+0

हां लेकिन अजीब बात यह है कि ऐसा लगता है कि इस स्थिति को नजरअंदाज कर दिया गया है। – cyrilPA

+1

खैर, एक और विकल्प 'UIGestureRecognizerDelegate'' इशारा करने योग्य पहचानकर्ता ShouldBegin: 'को लागू करना है और वहां स्पर्शों की संख्या जांचें। तो यदि यह दो स्पर्श है, तो 'वापस लौटें' – kovpas

उत्तर

7

मामले में यह अभी तक हल नहीं किया है, मैं समस्या मेरे लिए हल किया।

मैंने दो उंगली पैन जेस्चर और डिफ़ॉल्ट UIScrollView व्यवहार (कुछ तक स्क्रॉल करने) का पता लगाने के लिए UIScrollView में एक UIPanGestureRecognizer जोड़ा है, अभी भी काम करता है।

तो मैं क्या किया UIScrollView करने UIPanGestureReconizer जोड़ने के लिए है:

UIPanGestureRecognizer *pangestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(displayReloadIndicator:)]; 
pangestureRecognizer.minimumNumberOfTouches = 2; 
pangestureRecognizer.delegate = self; 
[self.scrollView addGestureRecognizer:pangestureRecognizer]; 
[pangestureRecognizer release]; 

इस के बाद मैं कोड कहा:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { 

    return YES; 
} 

इस के बाद, मैं पैन इशारा recognizers कार्रवाई विधि लागू।

- (void) displayReloadIndicator:(UIPanGestureRecognizer*) panGestureRecognizer { 

    UIGestureRecognizerState gestureRecognizerState = gestureRecognizer.state; 

    CGPoint translation = [gestureRecognizer translationInView:self.scv_bibgesamt]; 

    if (gestureRecognizerState == UIGestureRecognizerStateBegan) { 

     // create a UIView with all the Pull Refresh Headers and add to UIScrollView 
     // This is really much lines of code, but its simply creating a UIView (later you'll find a myRefreshHeaderView, which is my base view) and add UIElements e.g. UIActivityIndicatorView, a UILabel and a UIImageView on it 
     // In iOS 6 you will also have the possibility to add a UIRefreshControl to your UIScrollView 

    } 

    else if (gestureRecognizerState == UIGestureRecognizerStateEnded 
      || gestureRecognizerState == UIGestureRecognizerStateCancelled) { 

     if (translation.y >= _myRefreshHeaderView.frame.size.height + 12) { // _myRefreshHeaderView is my baseview 

     //so the UIScrollView has been dragged down with two fingers over a specific point and have been release now, so we can refresh the content on the UIScrollView 
     [self refreshContent]; 

     //animatly display the refresh view as the top content of the UIScrollView 
     [self.scrollView setContentOffset:CGPointMake(0, myRefreshHeaderView.frame.size.height) animated:YES]; 
    } 

    else { 

     //the UIScrollView has not been dragged over a specific point so don't do anything (just scroll back to origin) 
     [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; 

     //remove the view (because it's no longer needed) 
     [_myRefreshHeaderView removeFromSuperview]; 
    } 
} 

अद्यतन:

मामले में आप अपने navigationController से कड़ी चोट वापस कार्यक्षमता को एकीकृत करने की इच्छा हो सकती है, तो आप कोड निम्नलिखित एकीकृत करना चाहिए:

- (void) viewDidLoad { 

    [super viewDidLoad]; 


    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { 

     self.navigationController.interactivePopGestureRecognizer.enabled = YES; 

     self.navigationController.interactivePopGestureRecognizer.delegate = nil; 
    } 

    //setup view controller 
} 

और

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { 

    if (gestureRecognizer == _panGestureRecognizer 
     && [self.navigationController.viewControllers count] > 1) { 

     CGPoint point = [touch locationInView:self.view.window]; 

     if (point.x < 20 
      || point.x > self.view.window.frame.size.width - 20) { 

      return NO; 
     } 
    } 

    return YES; 
} 
+0

धन्यवाद @NicTesla – channi

+0

आपका स्वागत है :) – NicTesla

1

ई के लिए panRecognizer प्रतिनिधि लागू nable एक साथ UIScrollView UIGestureRecognizer

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{ 
    if (_panRecognizer == gestureRecognizer) { 
     if ([otherGestureRecognizer.view isKindOfClass:UIScrollView.class]) { 
      UIScrollView *scrollView = (UIScrollView *)otherGestureRecognizer.view; 
      if (scrollView.contentOffset.x == 0) { 
       return YES; 
      } 
     } 
    } 

    return NO; 
} 
संबंधित मुद्दे