PeekView supports peek, pop and preview actions for iOS devices without 3D Touch capibility

Related tags

Force Touch PeekView
Overview

PeekView

When implementing peek, pop and preview actions with 3D Touch, you may want to support such features for users accessing your app from older devices that don't provide 3D Touch capibility. PeekView hence can be used as an alternative in such case.

Preview Screenshot

(Please ignore the low resolution of the GIF. Try the demo for actual experience.)

Note

Things that need improving

  • Better solution for Objective-C integration (the current is sort of hacky!)
  • Better documenting in code
  • Content view panned: Smoother animation
  • Action style: Selected functionality
  • More customizable UI if needed (requests are welcome)
  • Bug fixes if any

Requirements

  • iOS 8 and later
  • Swift 5 & Xcode 10.2
  • If you wish to work with Swift 2.3, check out branch swift23

Getting Started

Install using CocoaPods

Just add the following line in to your pod file:

pod 'PeekView'

Manual Install

Drag and drop folder named Source in your project and you're done.

Usage

  • Add UILongPressGestureRecognizer to the view you want to peek (i.e table view cell, image, hypertext, etc.)
  • Create a UIViewController instance as the content of your peek view; then set your desired frame for the content view. It's recommended to leave a 15px padding for both left and right margin of your content view.
  • If you want to include preview actions, prepare an array containing title of the buttons and its preview style. Don't forget to prepare completion handlers for when each button is tapped.

Sample snippet:

  let options = [ 
    PeekViewAction(title: "Option 1", style: .Destructive), 
    PeekViewAction(title: "Option 2", style: .Default), 
    PeekViewAction(title: "Option 3", style: .Selected) ]
  PeekView().viewForController(
  parentViewController: self, 
  contentViewController: controller, 
  expectedContentViewFrame: frame, 
  fromGesture: gestureRecognizer, 
  shouldHideStatusBar: true, 
  withOptions: options, 
  completionHandler: { optionIndex in
                    switch optionIndex {
                    case 0:
                        print("Option 1 selected")
                    case 1:
                        print("Option 2 selected")
                    case 2:
                        print("Option 3 selected")
                    default:
                        break
                    }
                })

Be sure to check out the demo code for better understanding of the usage.

As for Objective-C integration, a slightly different static function should be used, in which the menuOptions array is expected to be an NSArray of NSDictionary's. Please check the snippet below:

    NSArray *options = @[@{@"Option 1": @(PeekViewActionStyleDefault)},
                         @{@"Option 2": @(PeekViewActionStyleDestructive)}];
    
    UIViewController *contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"previewVC"];
    
    [PeekView viewForControllerWithParentViewController:self
                                  contentViewController:contentViewController
                               expectedContentViewFrame:CGRectMake(0, 0, 280, 400)
                                            fromGesture:gesture
                                    shouldHideStatusBar:YES
                                            withOptions:options
                                      completionHandler:nil];

ARC

PeekView uses ARC. If you are using PeekView in a non-arc project, you will need to set a -fobjc-arc compiler flag on every PeekView source files. To set a compiler flag in Xcode, go to your active target and select the "Build Phases" tab. Then select PeekView source files, press Enter, insert -fobjc-arc and then "Done" to enable ARC for PeekView.

Contributing

Contributions for bug fixing or improvements are welcome. Feel free to submit a pull request.

Licence

PeekView is available under the MIT license. See the LICENSE file for more info.

Comments
  • missing a dismissPeekViewHandler

    missing a dismissPeekViewHandler

    I need to execute some code whenever PeekView is dismissed.

    Could you please add a 'dismissPeekViewHandler' parameter in your configureView function which is executed whenever the PeekView is dismissed, or something similar?

    thx

    opened by Dandiccf 3
  • objective C : not able to display

    objective C : not able to display

    Added to like this -- but it's not working .. how am i supposed to add .. little stuck here...

    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc]
                                          init];
    lpgr.minimumPressDuration = 1.0; //seconds
    lpgr.delegate = self;
    lpgr.allowableMovement = 80;
    [self.feedsTableView addGestureRecognizer:lpgr];
    NSArray *options = @[@{@"Option 1": @(PeekViewActionStyleDefault)},
                         @{@"Option 2": @(PeekViewActionStyleDestructive)}];
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"addpost"];
    
    [PeekView viewForControllerWithParentViewController:[self currentTopViewController]
                                  contentViewController:viewController
                               expectedContentViewFrame:CGRectMake(0, 0, 280, 400)
                                            fromGesture:lpgr
                                    shouldHideStatusBar:YES
                                            withOptions:options
                                      completionHandler:nil];
    
    opened by punithbm 2
  • Converted project to Swift 4.1

    Converted project to Swift 4.1

    I've run the conversion to Swift 4.1 using Xcode 9.3 and updated files.

    Also bumped the project version, so updating the pod in CocoaPods repo will require minimum amount of work ;)

    opened by mzygar 1
  • new method in calculating content view position

    new method in calculating content view position

    I made some changes in calculating content view position, it results in better animation especially when touched item is located near the top or bottom of the screen. Tested with the implementation in my app.

    opened by thaiduy 1
  • Demo Throws tons of errors

    Demo Throws tons of errors

    Mate, check out the demo project. It has like 13 errors. Update it to latest swift. could solve the problems. On the fly, I noticed the selector syntax hasn't been updated.

    opened by Mwiti 1
  • I think inside func contenViewPanned you have a bug (I THINK)

    I think inside func contenViewPanned you have a bug (I THINK)

    default: let pointOfHand = gestureRecognizer.location(in: self).y var centerOfContent = CGFloat(0) centerOfContent = pointOfHand - fromTouchToContentCenter

            updateContentViewFrame(centerOfContent)
        }
    

    this method panned content view with beginnig touching center if user touched to device top, animate will be not correct

    i did it like this default: let t = gestureRecognizer.translation(in: self) contentView?.transform = (contentView?.transform.translatedBy(x: 0, y: t.y))! gestureRecognizer.setTranslation(CGPoint.zero, in: self)

            updateContentViewFrame((contentView?.center.y)!)
        }
    
    opened by Nurka11 0
  • Landscape mode unable to move content view up to show buttons

    Landscape mode unable to move content view up to show buttons

    Everything works fine in portrait mode but when I rotate into landscape, I tap and hold, the content view is displayed, I continue to hold and start dragging up, the content view starts to drag up, but then it hits a wall and doesn't go move any higher and the buttons still aren't shown. If I release the long tap and then pan the content view, the buttons display fine.

    Edit: Figured it out. The long press gesture is part of a collection view cell so the initial long press is only changing it's location while inside the collection view cell (which is now in the background)

    opened by swemoney 0
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods šŸ¤“ https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
  • PeekViewAction always visible if triggering with finger

    PeekViewAction always visible if triggering with finger

    Hi there, I love your PeekView but I have an issue when using the PeekView.

    The PeekViewAction does not get visible by long pressing with the mouse (in simulator) and not moving, which is the expected behavior. But whenever I use the finger to trigger the PeekView I cannot keep absolutely immovable and so the PeekViewAction always gets visible and I have to touch the blurred part to dismiss the PeekView.

    Could you please add some tolerance for the touch panning to not trigger showing the PeekViewAction?

    opened by Dandiccf 0
Owner
Huong Do
Full-time debugger, part-time grammar nazi
Huong Do
Swift wrapper for iOS Home Screen Quick Actions (App Icon Shortcuts)

QuickActions Swift wrapper for iOS Home Screen Quick Actions This wrapper creates dynamic quick actions. It is possible to define static quick actions

Ricardo Pereira 251 Dec 29, 2022
JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop interactions on devices that do not natively support this kind of interaction.

JustPeek Warning: This library is not supported anymore by Just Eat. JustPeek is an iOS Library that adds support for Force Touch-like Peek and Pop in

Just Eat 68 Apr 4, 2021
Peek and Pop with backwards-compatibility

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, alm

Roy Marmelstein 2k Dec 8, 2022
ExpandingCollection is an animated material design UI card peek/pop controller.

EXPANDING COLLECTION An animated material design UI card peek/pop controller We specialize in the designing and coding of custom UI for Mobile Apps an

Ramotion 5.5k Jan 6, 2023
Will Powell 1.2k Dec 29, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022
RadialMenu is a custom control for providing a touch context menu (like iMessage recording in iOS 8) built with Swift & POP

RadialMenu Looking for help? For $150/hr I'll help with your RadialMenu problems including integrating it into your project. Email [email protected] t

Brad Jasper 297 Nov 27, 2022
SwiftUI, peek scrolling animation and card tapped animation, using GeometryReader

SwiftUI, peek scrolling animation and card tapped animation, using GeometryReader, follow the livestream tutorial by MengTo.

Terry Kuo 4 Jun 10, 2022
Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.

Create an easy to peek SwiftUI View to showcase your own data, catalog, images, or anything you'd like.

Peter Larson 17 Jun 27, 2022
null 4 May 22, 2022
The app provides additional actions for the Shortcuts app on macOS and iOS.

Actions Supercharge your shortcuts The app provides additional actions for the Shortcuts app on macOS and iOS. Submit action idea (Submit an issue bef

Sindre Sorhus 1.2k Dec 29, 2022
This repo shows how to setup and use GitHub Actions as a CI for Swift Packages

GACalc This repo shows how to setup and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib List of the all available envi

Michał Tynior 0 Nov 3, 2021
This repo shows how to set up and use GitHub Actions as a CI for Swift Packages

SwiftPackageWithGithubActionsAsCI This repo shows how to set up and use GitHub Actions as a CI for Swift Packages. Available environments on GitHib Li

Michał Tynior 0 Nov 3, 2021
Swift wrapper for iOS Home Screen Quick Actions (App Icon Shortcuts)

QuickActions Swift wrapper for iOS Home Screen Quick Actions This wrapper creates dynamic quick actions. It is possible to define static quick actions

Ricardo Pereira 251 Dec 29, 2022
SwiftUI library for a walkthrough or onboarding flow with tap actions

Concentric Onboarding iOS library for a walkthrough or onboarding flow with tap actions written with SwiftUI We are a development agency building phen

Exyte 955 Jan 4, 2023
Easy to use UITableViewCell implementing swiping to trigger actions.

SwipyCell Swipeable UITableViewCell inspired by the popular Mailbox App, implemented in Swift. Preview Exit Mode The .exit mode is the original behavi

Moritz Sternemann 249 Dec 5, 2022
SwiftUI library for a walkthrough or onboarding flow with tap actions

Concentric Onboarding iOS library for a walkthrough or onboarding flow with tap actions written with SwiftUI We are a development agency building phen

Exyte 956 Jan 4, 2023
One gesture, many actions. An evolution of Pull to Refresh.

MNTPullToReact MNTPullToReact is an extended evolution of the famous Pull to Refresh interaction. The main idea comes from a unique question: can the

Mention 777 Nov 20, 2022
Convenient UITableViewCell subclass that implements a swippable content to trigger actions (similar to the Mailbox app).

MCSwipeTableViewCell An effort to show how one would implement a UITableViewCell like the one we can see in the very well executed Mailbox iOS app. Pr

Ali Karagoz 3k Dec 16, 2022
Library for creating swipe actions for any SwiftUI View

SwipeActions Library for creating swipe actions for any SwiftUI View, similar to

Alexander Kraev 24 Dec 26, 2022