GithubHelp home page GithubHelp logo

ivanvorobei / splarkcontroller Goto Github PK

View Code? Open in Web Editor NEW
984.0 20.0 47.0 4.6 MB

Custom transition between controllers. Settings controller for your iOS app.

Home Page: https://opensource.ivanvorobei.io

License: MIT License

Swift 99.94% Ruby 0.06%
ui swift settings animation controller modal gester ux custom transition

splarkcontroller's Introduction

SPLarkController

About

Transition between controllers to top. You can change animatable height after presentation controller.

For presentation and dismissing using custom transition delegate.

You can set any content to bottom controller, like buttons or even collection as in preview. For implement settings as in preiew, see section Settings Controller.

If you like the project, don't forget to put star ★
Check out my other libraries:

Navigate

Requirements

Swift 4.2 & 5.0. Ready for use on iOS 10+

Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate using Xcode 12, specify it in File > Swift Packages > Add Package Dependency...:

https://github.com/ivanvorobei/SPLarkController

CocoaPods:

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate using CocoaPods, specify it in your Podfile:

pod 'SPLarkController'

Manually

If you prefer not to use any of dependency managers, you can integrate manually. Put Sources/ProjectName folder in your Xcode project. Make sure to enable Copy items if needed and Create groups.

Usage

Presenting

Create controller and call func presentAsLark:

import UIKit
import SPLarkController

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

        let controller = UIViewController()
        self.presentAsLark(controller)
    }
}

If you want customize controller (set custom height and other), create controller and set transitioningDelegate to SPLarkTransitioningDelegate object. Use present or dismiss functions:

let controller = UIViewController()
let transitionDelegate = SPLarkTransitioningDelegate()
controller.transitioningDelegate = transitionDelegate
controller.modalPresentationStyle = .custom
controller.modalPresentationCapturesStatusBarAppearance = true
self.present(controller, animated: true, completion: nil)

Please, do not init SPLarkTransitioningDelegate like this:

controller.transitioningDelegate = SPLarkTransitioningDelegate()

You will get an error about weak property.

Height

Parameter customHeight sets custom height for modal controller. Default is nil:

transitionDelegate.customHeight = 350

Change Height

For change height after presenting use with code:

if let presentationController = self.presentationController as? SPLarkPresentationController {
    presentationController.updateHeight(600)
}

You can see how it work in Example folder. I am plase ready-use project.

Settings Controller

You can simple implement settings controller as in preview. You need extend from SPLarkSettingsController and implement all methods for it. See class for more details.

class SettingsController: SPLarkSettingsController {}

Snapshots

The project uses a snapshot of the screen in order to avoid compatibility and customisation issues. Before controller presentation, a snapshot of the parent view is made, and size and position are changed for the snapshot. Sometimes you will need to update the screenshot of the parent view, for that use static func:

SPLarkController.updatePresentingController(modal: controller)

and pass the controller, which is modal and uses SPLarkTransitioningDelegate

Modal presentation of other controller

If you want to present modal controller on SPLarkController, please set:

controller.modalPresentationStyle = .custom

It’s needed for correct presentation and dismissal of all modal controllers.

Other Projects

I love being helpful. Here I have provided a list of libraries that I keep up to date. For see video previews of libraries without install open opensource.ivanvorobei.by website.
I have libraries with native interface and managing permissions. Also available pack of useful extensions for boost your development process.

Russian Community

Подписывайся в телеграмм-канал, если хочешь получать уведомления о новых туториалах.
Со сложными и непонятными задачами помогут в чате.

Видео-туториалы выклыдываю на YouTube:

Tutorials on YouTube

splarkcontroller's People

Contributors

alexmodrono avatar ivanvorobei avatar kohdepitcher avatar kraj011 avatar rminsh avatar wiencheck avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

splarkcontroller's Issues

iOS 15 - Presented view controller appears briefly in front of the snapshot before transition

Coming back to this library to give it another go in a project but I noticed a visual bug with the presentation as it briefly flashes the target view controller in front of the snapshot before the snapshot animates up to reveal the underlying view controller.

I've attached a video of the bug in the simulator when showing the destination view controller.
Note that it doesn't happen all the time and also happens on a physical device.

Simulator.Screen.Recording.-.iPhone.12.-.2022-05-14.at.17.22.19.mp4

Here is the code that I'm using to present the view controller:
let transitionDelegate = SPLarkTransitioningDelegate()
transitionDelegate.customHeight = self.view.frame.height * 0.60
palleteVC.transitioningDelegate = transitionDelegate
palleteVC.modalPresentationStyle = .custom
palleteVC.modalPresentationCapturesStatusBarAppearance = true

self.present(palleteVC, animated: true, completion: nil)

This never happened when I tried out this library for another project back in 2019.
Not sure if its the UIHostingViewController that is being presented or if its something to do with iOS 15

Thanks!

update parent controller

hi sir
i go the lark controller with press a button
and in lark controller i type a text in text field and then i press a button
and i want send my text to parent controller
when i back to parent controller nothings changed
whats my problem ?
here is my code
thanks
`import UIKit
import SPLarkController
class ViewController: UIViewController {

@IBOutlet weak var labelResult: UILabel!
internal var  labelText = ""
@IBAction func goToLarkController(_ sender: Any) {
    
    let vc = storyboard?.instantiateViewController(withIdentifier: "ViewController2")
    let transitionDelegate = SPLarkTransitioningDelegate()
    vc?.transitioningDelegate = transitionDelegate
    vc?.modalPresentationStyle = .custom
    vc?.modalPresentationCapturesStatusBarAppearance = true
    self.present(vc!, animated: true, completion: nil)
}

override func viewDidLoad() {
    super.viewDidLoad()

    labelResult.text = labelText
    
}}`

`import UIKit
import SPLarkController
class ViewController2: UIViewController {

@IBOutlet weak var t: UITextField!
@IBAction func act(_ sender: UIButton) {
    let backToMainController = storyboard?.instantiateViewController(withIdentifier: "ViewController") as! ViewController
    backToMainController.labelText = t.text!
    let transitionDelegate = SPLarkTransitioningDelegate()
    backToMainController.transitioningDelegate = transitionDelegate
    dismiss(animated: true, completion: nil)
    SPLarkController.updatePresentingController(modal: backToMainController)
}

override func viewDidLoad() {
    super.viewDidLoad()

}

}`

Objective-c support

I know u have just created it, an it's amazing, so please, consider to add objective-c support

Any way to change height after presenting?

Although this is not part of the current implementation, would you have any suggestions on how to change the view controller's height after it has been presented?

An example use case for this behavior would be a settings view controller with a textfield which moves up when the keyboard appears.

refresh parent.

Hello, after i dismiss i want to refresh the parent controller. But it does not work.

let controller = UIViewAcknoledge() controller.modalPresentationStyle = .custom SPLarkController.updatePresentingController(modal: controller) self.presentAsLark(controller)

Example project not compiling

  1. Build input file cannot be found:
    TestSwiftUIView.swift

Beside that:

  1. let controller = viewCtrl ?!

  2. self.button.addTarget(self, action: #selector(self.presentLarkController), for: .touchUpInside)
    Selector calling iOS 13.0+ available method needs to be in #available check as well.

Custom height for Lark presenter doesn't actually make the sub VC same height as custom height

Hi, been trying to use this library to present one of my own custom VCs but I can't work out why the height of the presented view controller using lark doesn't have the same height as the custom height provided to the transition delegate. For example, ive told the delegate to be half the screen size which works for the transition but the view controller that is presented is still the same height as the screen height. This means that any views pinned to the bottom of the safe area for example are missing when using Lark.

in this screen shot, you can see that the pink button is cut off even though it is constrained to be centre vertical and centre horizontal.
IMG_1852

Is there anyway to force the presented view controller's frame to match the frame of the lark transition? I've tried messing with the code in the library and can't seem to get it to work. I've noticed that frameOfPresentedViewInContainerView method never gets called in the presentation controller.
override var frameOfPresentedViewInContainerView: CGRect { guard let containerView = containerView else { return .zero } print("frameOfPresentedViewInContainerView") return CGRect(x: 0, y: containerView.bounds.height - self.height, width: containerView.bounds.width, height: self.height) }

Some classes need to be public to work in SPM

When using your code (which is great) with SwiftPackageManger, some Classes can not be accessed (like SPLarkPresentationController).

Think they need marked as public to be available in the package.

Issue with Swift Package Manager support

Big thanks for this beautiful library! Unfortunately I cannot get it to install via SPM, I get the error saying Source files for target SPLark should be located under 'Sources/SPLark', or a custom sources path can be set with the 'path' property in Package.swift

Zrzut ekranu 2020-06-4 o 21 54 52

Round snapshot view corners

Hi, thanks for beautiful library!
Is there a way to round snapshot view corners for this case?
My main view consists of tab bar + scroll view.

image

Thanks in advance.

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.