Code Monkey home page Code Monkey logo

floatingshowable's Introduction

🎈FloatingShowable

This is a support kit that helps you develop a picture-in-picture-like view.

FloatingShowable ios MIT Carthage compatible Build Status codecov

Introduction

FloatingShowable is a UIKit library for a more concise picture-in-picture implementation. Acceleration control, which tends to be complicated, is also supported.

Features:

  • It was developed inspired by the picture-in-picture introduced in iOS14.
  • Movement that takes acceleration into account is possible
  • Various parameters related to shadow and movement animation can be customized
  • With this, picture-in-picture will be available in the app even on devices with iOS13 or lower.

Installation

CocoaPods

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'FloatingShowable'
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

$ pod install

Carthage

Add this to Cartfile.

# Cartfile
github "AkkeyLab/FloatingShowable"

Run this script to install it.

$ carthage update --platform iOS

Simplest Usage

  1. Please import FloatingShowable
  2. The target UIViewController must be FloatingShowable compliant
import FloatingShowable
import UIKit

final class FloatingViewController: UIViewController, FloatingShowable {
    var position: FloatingPosition = .bottomRight

    var frameSize: CGSize {
        CGSize(width: 160, height: 90)
    }

    var window: UIWindow {
        UIApplication.shared.windows.filter { $0.isKeyWindow }.first ?? UIWindow()
    }
}
  1. Call the show function from a FloatingShowable compliant object
  2. Don't forget to call dismiss function when you want to destroy the parent instance
final class ViewController: UIViewController {
    private var floatingScreen = FloatingViewController()

    deinit {
        floatingScreen.dismiss(isScaleChange: true)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        floatingScreen.show()
    }
}

For the simplest implementation, picture-in-picture can be achieved in just four steps.

Change the movement range

  1. Change stayArea value
  2. Call updateLayout function when the target object is already displayed
final class ViewController: UIViewController {
    private var floatingScreen = FloatingViewController()
    private var isBottomInsetAdd = false {
        didSet {
            floatingScreen.stayArea.bottom = isBottomInsetAdd ? 100 : 16
            floatingScreen.updateLayout()
        }
    }
}

After changing the value, if the target object is in the no-entry area, it will move with animation.

Requirements

env version
Swift 5.x
Xcode 12.x
iOS 11.0

License

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

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.