A framework which helps you attach observers to `UIView`s to get updates on its frame changes

Related tags

UI FrameObserver
Overview

FrameObserver is a framework that lets you attach observers to any UIView subclass and get notified when its size changes. It doesn't use any Method Swizzling or KVO so it'll be perfectly safe to use. It is especially useful when dealing with entities that require you to supply a CGRect to them, e.g CAGradientLayer.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

Then, to add FrameObserver to your project, specify FrameObserver in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '' do
    pod 'FrameObserver'
end

Usage

  • Using closures:
view.addFrameObserver { frame, bounds in // get updates when the size of view changes
    print("frame", frame, "bounds", bounds)
}
  • Using the delegate pattern:
class SomeViewController: UIViewController, FrameChangeDelegate {

    func frameChangeDelegateDidChange(for view: UIView, _ frame: CGRect, _ bounds: CGRect) {
        if view == self.view {
            print("frame", frame, "bounds", bounds)
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        view.addFrameObserver(with: self)
    }

}

You can call these on any UIView subclass, such as UIButton, UIStackView, etc.

The underlying implementation of this framework adds a totally invisibile, untappable view as a subview of the view you want to get notified about its frame. Thus, if you attach an observer to a UIView subclass, and for whatever reason remove all of its subviews, make sure you add the observer again.

override func viewDidLoad() {
    super.viewDidLoad()
    view.addFrameObserver(with: self)

    for subview in view.subviews {
        subview.removeFromSuperview()
    }

    // the observer no longer exists, recreating it again
    view.addFrameObserver(with: self)
}

Other functions:

  • func removeFrameObserver(): Removes the current observer, if any. There's no need to call this in the deinit of your classes.
  • func hasFrameObserver() -> Bool: Returns true if the view has a frame observer.

License

FrameObserver is released under the MIT license. Check the LICENSE file for more details.

You might also like...
High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton, Promise and more.

SwiftyUI High performance and lightweight UIView, UIImage, UIImageView, UIlabel, UIButton and more. Features SwiftyView GPU rendering Image and Color

Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

Custom Beautiful UIView For Handling IDs in iOS
Custom Beautiful UIView For Handling IDs in iOS

IDView Custom Beautiful UIView For Handling IDs in iOS Setup Set the placeholder images for the front and back faces. override func viewDidLoad()

Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements
Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements

SwiftUIKitView Easily use UIKit views in SwiftUI. Convert UIView to SwiftUI View Create Xcode Previews from UIView elements SwiftUI functional updatin

Easily add drop shadows, borders, and round corners to a UIView.

Easily add drop shadows, borders, rounded corners to a UIView. Installation CocoaPods Add the follwing to your Podfile: pod 'Shades' Usage Storyboard

Anchorage - Single file UIView drag and drop system
Anchorage - Single file UIView drag and drop system

anchorage Single file UIView drag and drop system anchors.mp4 License Copyright

A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval.
A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval.

MultiStepSlider A custom UIControl which functions like UISlider where you can set multiple intervals with different step values for each interval. Th

A framework that provides CurtainController. CurtainController is a container view controller that implements a content-curtain interface. You can find a similar implementation in applications like Apple Maps, Find My, Stocks, etc. Someone calls it A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed flag
A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed flag

HidesNavigationBarWhenPushed A library, which adds the ability to hide navigation bar when view controller is pushed via hidesNavigationBarWhenPushed

Owner
null
Newly is a drop in solution to add Twitter/Facebook/Linkedin style, new updates/tweets/posts available button

Newly is a drop in solution to add Twitter/Facebook/Linkedin style, new updates/tweets/posts available button. It can be used to notify user about new content availability and can other actions can be triggers using its delegate method.

Dhiraj Rajendra Jadhao 197 Sep 22, 2022
DGFadingLabel - A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame

A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame.

donggyu 4 Jun 10, 2022
A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles

A drop-in universal library helps you to manage the navigation bar styles and makes transition animations smooth between different navigation bar styles while pushing or popping a view controller for all orientations. And you don't need to write any line of code for it, it all happens automatically.

Zhouqi Mo 3.3k Dec 21, 2022
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

Wilson Ding 334 Jan 7, 2023
A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView and iPhone X safe area support for content reloading. Built for iOS 10 and later.

Arale A custom stretchable header view for UIScrollView or any its subclasses with UIActivityIndicatorView support for reloading your content. Built f

Putra Z. 43 Feb 4, 2022
Full configurable spreadsheet view user interfaces for iOS applications. With this framework, you can easily create complex layouts like schedule, gantt chart or timetable as if you are using Excel.

kishikawakatsumi/SpreadsheetView has moved! It is being actively maintained at bannzai/SpreadsheetView. This fork was created when the project was mov

Kishikawa Katsumi 34 Sep 26, 2022
Simple battery shaped UIView

BatteryView Simple battery shaped UIView. Usage let batteryView = BatteryView(frame: smallRect) batteryView.level = 42 // anywhere in 0...100 batteryV

Yonat Sharon 50 Sep 19, 2022
Elissa displays a notification on top of a UITabBarItem or any UIView anchor view to reveal additional information.

Elissa Attach a local notification to any UIView to reveal additional user guidance. Usage Example Per default, Elissa will try to align to the center

null 169 Aug 14, 2022
UIView and CGRect extension that adds properties to manipulate them efficiently

Geometry Geometry is a UIView and CGRect extension that lets you work with view and rect geometry easier. It adds the following properties to UIView:

Tuomas Artman 92 Sep 7, 2022
An iOS Library that makes shadows management easy on UIView.

ShadowView is an iOS Shadow library that makes view's shadow implementation easy and sweet ?? ?? . Add simple shadows to add a gaussian blurred projec

Pierre 404 Dec 8, 2022