Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can override </p> <pre><code>-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch </code></pre> <p>to better control when the PageViewController should receive the touch and not. Look at "Preventing Gesture Recognizers from Analyzing Touches" in <a href="http://developer.apple.com/library/IOs/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html#//apple_ref/doc/uid/TP40009541-CH6-SW1" rel="nofollow noreferrer" title="Gesture Recogizers">Dev API Gesture Recognizers</a></p> <p>My solution looks like this in the RootViewController for the UIPageViewController:</p> <p>In viewDidLoad:</p> <pre><code>//EDITED Need to take care of all gestureRecogizers. Got a bug when only setting the delegate for Tap for (UIGestureRecognizer *gR in self.view.gestureRecognizers) { gR.delegate = self; } </code></pre> <p>The override:</p> <pre><code>-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { //Touch gestures below top bar should not make the page turn. //EDITED Check for only Tap here instead. if ([gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) { CGPoint touchPoint = [touch locationInView:self.view]; if (touchPoint.y &gt; 40) { return NO; } else if (touchPoint.x &gt; 50 &amp;&amp; touchPoint.x &lt; 430) {//Let the buttons in the middle of the top bar receive the touch return NO; } } return YES; } </code></pre> <p>And don't forget to set the RootViewController as UIGestureRecognizerDelegate.</p> <p>(FYI, I'm only in Landscape mode.)</p> <p>EDIT - The above code translated into Swift 2:</p> <p>In viewDidLoad:</p> <pre><code>for gr in self.view.gestureRecognizers! { gr.delegate = self } </code></pre> <p>Make the page view controller inherit <code>UIGestureRecognizerDelegate</code> then add:</p> <pre><code>func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -&gt; Bool { if let _ = gestureRecognizer as? UITapGestureRecognizer { let touchPoint = touch .locationInView(self.view) if (touchPoint.y &gt; 40 ){ return false }else{ return true } } return true } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload