Code Monkey home page Code Monkey logo

klcpopup's Introduction

KLCPopup

KLCPopup is a simple and flexible iOS class for presenting any custom view as a popup. It includes a variety of options for controlling how your popup appears and behaves.

##Installation

  • Drag the KLCPopup/KLCPopup folder into your project.
  • #import "KLCPopup.h" where appropriate.

##Usage

(see sample Xcode project in /KLCPopupExample)

Creating a Popup

Create a popup for displaying a UIView using default animations and behaviors (similar to a UIAlertView):

+ (KLCPopup*)popupWithContentView:(UIView*)contentView;

Or create a popup with custom animations and behaviors. Customizations can also be accessed via properties on the popup instance:

+ (KLCPopup*)popupWithContentView:(UIView*)contentView
						 showType:(KLCPopupShowType)showType
					  dismissType:(KLCPopupDismissType)dismissType
						 maskType:(KLCPopupMaskType)maskType
		 dismissOnBackgroundTouch:(BOOL)shouldDismissOnBackgroundTouch
			dismissOnContentTouch:(BOOL)shouldDismissOnContentTouch;

Note: You may pass nil for contentView when creating the popup, but you must assign a contentView to the popup before showing it!

Also you must give your contentView a size before showing it (by setting its frame), or it must size itself with AutoLayout.

Showing a Popup

Show popup in middle of screen.

- (void)show;

There are two ways to control where your popup is displayed:

  1. Relative layout presets (see KLCPopup.h for options).

     - (void)showWithLayout:(KLCPopupLayout)layout;
    
  2. Explicit center point relative to a view's coordinate system.

     - (void)showAtCenter:(CGPoint)center inView:(UIView*)view;
    

If you want your popup to dismiss automatically (like a toast in Android) you can set an explicit duration:

- (void)showWithDuration:(NSTimeInterval)duration;

Dismissing a Popup

There are a few ways to dismiss a popup:

If you have a reference to the popup instance, you can send this message to it. If animated, then it will use the animation specified in dismissType. Otherwise it will just disappear:

- (void)dismiss:(BOOL)animated;

If you lost your reference to a popup or you want to make sure no popups are showing, this class method dismisses any and all popups in your app:

+ (void)dismissAllPopups;

Also you can call this category method from UIView(KLCPopup) on your contentView, or any of its subviews, to dismiss its parent popup:

- (void)dismissPresentingPopup; // UIView category

Customization

Animation used to show your popup:

@property (nonatomic, assign) KLCPopupShowType showType;

Animation used to dismiss your popup:

@property (nonatomic, assign) KLCPopupDismissType dismissType;

Mask prevents touches to the background from passing through to views below:

@property (nonatomic, assign) KLCPopupMaskType maskType;

Popup will automatically dismiss if the background is touched:

@property (nonatomic, assign) BOOL shouldDismissOnBackgroundTouch;

Popup will automatically dismiss if the contentView is touched:

@property (nonatomic, assign) BOOL shouldDismissOnContentTouch;

Override alpha value for dimmed background mask:

@property (nonatomic, assign) CGFloat dimmedMaskAlpha;	

Blocks

Use these blocks to synchronize other actions with popup events:

@property (nonatomic, copy) void (^didFinishShowingCompletion)();

@property (nonatomic, copy) void (^willStartDismissingCompletion)();

@property (nonatomic, copy) void (^didFinishDismissingCompletion)();

Example

UIView* contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor orangeColor];
contentView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
	
KLCPopup* popup = [KLCPopup popupWithContentView:contentView];
[popup show];

Notes

Interface Orientation

KLCPopup supports Portrait and Landscape by default.

Deployment

KLCPopup requires iOS 7.

Devices

KLCPopup supports iPhone and iPad.

ARC

KLCPopup requires ARC.

TODO

  • Add support for keyboard show/hide.
  • Add support for drag-to-dismiss.
  • Add 'blur' option for background mask

##Credits KLCPopup was created by Jeff Mascia and the team at Kullect, where it's used in the Shout Photo Messenger app. Aspects of KLCPopup were inspired by Sam Vermette's SVProgressHUD.

klcpopup's People

Contributors

jmascia avatar nicopuri avatar

Watchers

James Cloos avatar Jeamin, Wong 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.