Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm working on a similar feature in an app of mine, and here's what I've figured out so far - I'm not done yet, but here's a way to get started.</p> <p>First, I'm assuming you're developing for iOS 7 only - while it's totally possible to build this for iOS 6, you can take a couple of neat shortcuts if you're only developing for 7.</p> <p>The forward/backward gestures are handled with a <code>UIScreenEdgePanGestureRecognizer</code>. You add it to the web view like so:</p> <pre><code> UIScreenEdgePanGestureRecognizer *bezelSwipeGestureRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(swipeBack:)]; bezelSwipeGestureRecognizer.edges = UIRectEdgeLeft; bezelSwipeGestureRecognizer.delegate = self; [self.view addGestureRecognizer:bezelSwipeGestureRecognizer]; UIView *invisibleScrollPreventer = [UIView new]; invisibleScrollPreventer.frame = CGRectMake(0, 0, 10, self.view.frame.size.height); [self.view addSubview:invisibleScrollPreventer]; </code></pre> <p>That'll add the back-swipe gesture. The tricky part is that invisibleScrollPreventer - it's an imperfect hack, but it'll avoid scrolling your web view instead of doing the back action. (There's probably a better way to handle that, but that's my current solution.)</p> <p>In your <code>swipeBack:</code> method, you'll do something like the following:</p> <pre><code>-(void)swipeBack:(UIScreenEdgePanGestureRecognizer *)recognizer { if (recognizer.state == UIGestureRecognizerStateEnded) { if (_webView.canGoBack) { [_webView goBack]; } } } </code></pre> <p>You'd do these same things to add a <code>goForward:</code> method to your web view.</p> <p>The <em>real</em> trick is getting the web page that you're going back to (or forward to) to appear onscreen as you're swiping back or forward, as in Safari in iOS 7. I'm not 100% sure how to do this (I haven't built that function yet in my app, but I will soon) and I'm guessing it's an iOS 7 <a href="https://coderwall.com/p/56wcfq">snapshotView</a> with some darkening applied.</p> <p>Depending on how you choose to build this, you may also want to check out <a href="http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/">custom navigation transitions in iOS 7</a>. I don't know if that's required for this problem, but it might be. </p> <p>Good luck!</p>
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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