Skip to content
This repository was archived by the owner on Nov 7, 2022. It is now read-only.

Repository files navigation

EventBox

Build StatusCarthage compatible

Provides an interface for use the addObserverForName safely and easily.

Features

  • Comprehensive Unit Test Coverage
  • Carthage support
  • Thread-safe

Usage

Minimum

EventBox.onMainThread(target, name:"reload"){ _ in
// UI
}EventBox.onBackgroundThread(target, name:"reload"){ _ in
// API Access
}EventBox.post("reload")EventBox.off(target) // Remove all the observers of the target
EventBox.off(target,"reload") // Remove observers of the same name of the target

Sender

EventBox.onMainThread(target, name:"getStatus"){ n in
// API Access
letstatus= n.object asTwitterStatus // sender
}letstatus=TwitterStatus()EventBox.post("getStatus", sender: status)

Handling the keyboard notifications

// MARK: - View Life Cycle
overridefunc viewWillAppear(animated:Bool){
super.viewWillAppear(animated)EventBox.onMainThread(self, name: UIKeyboardWillShowNotification, handler:{ n inself.keyboardWillChangeFrame(n, showsKeyboard:true)})EventBox.onMainThread(self, name: UIKeyboardWillHideNotification, handler:{ n inself.keyboardWillChangeFrame(n, showsKeyboard:false)})}overridefunc viewDidDisappear(animated:Bool){
super.viewDidDisappear(animated)EventBox.off(self)}
// MARK: - Keyboard Event Notifications
func keyboardWillChangeFrame(notification:NSNotification, showsKeyboard:Bool){letuserInfo= notification.userInfo!
letanimationDuration=(userInfo[UIKeyboardAnimationDurationUserInfoKey]asNSNumber).doubleValue
letkeyboardScreenEndFrame=(userInfo[UIKeyboardFrameEndUserInfoKey]asNSValue).CGRectValue()if showsKeyboard {letorientation:UIInterfaceOrientation=UIApplication.sharedApplication().statusBarOrientation
if(orientation.isLandscape){
containerViewButtomConstraint.constant = keyboardScreenEndFrame.size.width
}else{
containerViewButtomConstraint.constant = keyboardScreenEndFrame.size.height
}}else{
containerViewButtomConstraint.constant =0}self.view.setNeedsUpdateConstraints()UIView.animateWithDuration(animationDuration, delay:0, options:.BeginFromCurrentState, animations:{self.containerView.alpha = showsKeyboard ?1:0self.view.layoutIfNeeded()}, completion:{ finished inif !showsKeyboard {self.view.hidden =true}})}

Requirements

  • iOS 8.0+
  • Xcode 7.3+

Installation

Carthage

Add the following line to your Cartfile

github "s-aska/EventBox"

CocoaPods

Add the following line to your Podfile

use_frameworks!
pod 'EventBox'

License

EventBox is released under the MIT license. See LICENSE for details.

About

EventBox is yet another notification library written in Swift.

Resources

Stars

19 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages