Coder Social home page Coder Social logo

peekpop's Introduction

PeekPop - backwards-compatible peek and pop in Swift

Build Status Version Carthage compatible

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 80% of iOS users are on older devices.

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

Features

          |  Features

--------------------------|------------------------------------------------------------ :star2: | Uses Apple's beautiful peek and pop interaction for devices with 3D touch. :point_up_2: | Custom Pressure-sensitive tap recognition for older devices. :heartpulse: | Faithful recreation of the peek and pop animation on older devices. :iphone: | Almost identical API to Apple's. :eight: | 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.

Setting up with CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
pod 'PeekPop', '~> 0.1'

Setting up with Carthage

Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate PeekPop into your Xcode project using Carthage, specify it in your Cartfile:

github "marmelroy/PeekPop"

Inspiration

peekpop's People

Contributors

marmelroy avatar albinekcom avatar bartoszpolaczykmw avatar

Watchers

Chew Chit Siang avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.