Latest 1.1.0
Homepage https://github.com/amerhukic/OrientationTracker
License MIT
Platforms ios 8.0
Frameworks UIKit, CoreMotion
Authors

Logo


Pod Version


License


Twitter: @hukicamer

OrientationTracker is a Core Motion based library for tracking device orientation changes. It also works for devices with orientation-lock turned on. You can subscribe to orientation change notifications and react accordingly.

Requirements

  • iOS 8.0+
  • Xcode 10.2
  • Swift 5.0

Usage

To start device orientation tracking use OrientationTracker you simply invoke the startDeviceOrientationTracking method, preferably in AppDelegate :

DeviceOrientationDetector.shared.startDeviceOrientationTracking()

You then add an observer for the OrientationTracker.deviceOrientationChangedNotification and react to orientation changes:

NotificationCenter.default.addObserver(self, selector: #selector(updateViews), name: DeviceOrientationDetector.deviceOrientationChangedNotification, object: nil)

You can access the current orientation using the currentDeviceOrientation property.

To stop receiving notifications use the stopDeviceOrientationTracking method:

DeviceOrientationDetector.shared.stopDeviceOrientationTracking()

If your app supports portrait mode only, you can use the affineTransform property to rotate views when the orientation changes:

UIView.animate(withDuration: 0.2) {
    self.imageView.transform = DeviceOrientationDetector.shared.affineTransform
}

Example

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

Installation

CocoaPods

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

$ gem install cocoapods

To integrate OrientationTracker into your Xcode project using CocoaPods, specify it in your Podfile:

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

target '<Your Target Name>' do
    pod 'OrientationTracker'
end

Then, run the following command:

$ pod install

Author

Amer Hukić

License

OrientationTracker is licensed under the MIT license. Check the LICENSE file for details.

Latest podspec

{
    "name": "OrientationTracker",
    "version": "1.1.0",
    "summary": "Track orientation changes even when the device is orientation-locked",
    "description": "OrientationTracker is a library for tracking device orientation changes even for devices with orientation-lock turned on. You can subscribe to orientation change notifications and react accordingly. Using the affineTransform property you can rotate the views to follow the orientation change.",
    "homepage": "https://github.com/amerhukic/OrientationTracker",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Amer Hukiu0107": "[email protected]"
    },
    "source": {
        "git": "https://github.com/amerhukic/OrientationTracker.git",
        "tag": "1.1.0"
    },
    "social_media_url": "https://twitter.com/hukicamer",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "OrientationTracker/Classes/**/*",
    "frameworks": [
        "UIKit",
        "CoreMotion"
    ],
    "swift_version": "5.0"
}

Pin It on Pinterest

Share This