PeekPop 1.0.0

PeekPop 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Roy Marmelstein.



PeekPop 1.0.0

PeekPop - backwards-compatible peek and pop in Swift

PeekPop

Peek and Pop is a great new iOS feature introduced with iPhone 6S and 6S+ that allows you to easily preview content using 3D touch.

Sadly, almost 60% of iOS users are on older devices.

PeekPop is a Swift framework that brings backwards-compatibility to Peek and Pop.

Features

Features
🌟 Uses Apple’s beautiful peek and pop interaction for devices with 3D touch.
👆 Custom Pressure-sensitive tap recognition for older devices.
💗 Faithful recreation of the peek and pop animation on older devices.
📱 Almost identical API to Apple’s.
8️⃣ Runs on all iOS8+ devices.

Missing features:

  • Support for peek and pop preview actions in devices that don’t have 3D touch.

Usage

Import PeekPop at the top of the Swift file.

import PeekPop

Create a PeekPop object, register your view controller for handling the peek and specify the source view. You will also need to declare that your view controller will conform to the PeekPopPreviewingDelegate protocol.

class MyViewController: UIViewController, PeekPopPreviewingDelegate {

    var peekPop: PeekPop?

    override func viewDidLoad() {
        peekPop = PeekPop(viewController: self)
        peekPop?.registerForPreviewingWithDelegate(self, sourceView: collectionView)
    }

PeekPopPreviewingDelegate requires implementing two simple functions. You will need to tell it what view controller to present for peeking purposes with:

    func previewingContext(_ previewingContext: PreviewingContext, viewControllerForLocation location: CGPoint) -> UIViewController?

…and you will need to tell it how to commit the preview view controller at the end of the transition with:

    func previewingContext(_ previewingContext: PreviewingContext, commitViewController viewControllerToCommit: UIViewController)

How does it work?

In devices without 3D touch, PeekPop recognizes pressure on the screen by monitoring significant changes in UITouch’s majorRadius value.

It assumes that by pressing harder on your iPhone, more of the surface area of your finger is in contact with the screen. This is true in the majority of cases.

Inspiration