GithubHelp home page GithubHelp logo

miller-ms / mmslayeredview Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 5.22 MB

A view that supports setting a background view and layering one or more subviews that can be user repositioned and resized. Could be used for creating an application to decorate an image with stickies.

License: MIT License

Swift 68.56% Ruby 2.76% Objective-C 1.93% Shell 26.75%

mmslayeredview's Introduction

MMSLayeredView

CI Status Version License Platform Readme Score

This MMSLayeredView class provides the features for layering UIViews on a background view and saving the composite image to a png file. The layered views can be moved, resized, and scaled within the confines of the view's frame.

Example

## Basic Usage To run the example project, clone the repo, and run `pod install` from the Example directory first.

Create a MMSLayeredView object. Add it to a subview of one of the application's UIViewController subclasses. Or in Interface Builder add a UIView to a subview of one of the UIViewControllers. In the Identity Inspector, select the class MMSLayeredView. Size it as you see fit for your application's needs.

Add a background view to the object. The background view can be a UIView or any subclass of UIView. Typically, you would add a UIImageView as the background view. Call the method addBackgroundView to set the background view.

override func viewDidLoad() {
    super.viewDidLoad()

    let exampleLayeredView = MMSLayeredView.init(frame: CGRectMake(20.0, 20.0, 100.0, 100.0))

    view.addSubview(exampleLayeredView)

    let backgroundImage = UIImage.init(named: "example.jpg")

    let backgroundView = UIImageView(image: backgroundImage)

    backgroundView.contentMode = .ScaleToFill

    sourceView.addBackgroundView(backgroundView)

}

addBackgroundImage adds the view to the subview, resizes the height and width to match the dimensions of exampleLayeredView and sets the frame's origin to (0,0).

Once the background view is set, all subviews added will display above the background view in the z-order. The background view can be set in a sequence with respect to adding subviews; it will always display behind all the subviews in the z-order.

Set a unique tag for the view to access any one of the subviews with the method:

    viewWithTag(tag:Int)

Add, remove, and reorder subviews to the layered view with UIView view hiearchy methods:

    addSubview(view:UIView)

    removeFromSuperview()

    insertSubview(view:UIView, atIndex: Int)

    insertSubview(view: UIView, aboveSubview: UIView)

    insertSubview(view: UIView, belowSubview: UIView)

    exchangeSubviewAtIndex(index1: Int, withSubviewAtIndex: Int)

    sendSubviewToBack(view: UIView)

    bringSubviewToFront(view: UIView)

The user selects one of the subviews for the focus of application operations by tapping the view. When tapped the view shows it has focus by filling the area outside it's perimeter with a translucent black. To get the UIView with focus access the property:

public var viewWithFocus: UIView?

Finally, this class supports the capability for merging the background view and subviews into image. With this feature, you can use the class to build applications providing the feature to layer text over images, decorate images with stickers, or both. This is the public method supporting export to image:

public func mergeTextAndImage() -> UIImage?

User Interaction

This class gives the application user the following operations:

  • Scale Subview: Pinch gesture.
  • Move Subview: Double tap to give move focus to the view then drag it.
  • Size Subview: One finger drag gesture to size dimensions independently.
  • Give Subview Focus: One finger tap gesture gives focus to a subview and removes it when it already has focus. Tap the background view to give it focus.

Requirements

  • MMSLayeredView requires iOS 8.3 or later.
  • Swift 3.0

Installation

MMSLayeredView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "MMSLayeredView"

Author

William Miller, [email protected]

License

This project is is available under the MIT license. See the LICENSE file for more info. Add attibution by linking to the project page is appreciated.

mmslayeredview's People

Contributors

miller-ms avatar

Watchers

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.