• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PADTiltViewController

PADTiltViewController adds device tilt capability to one directional scroll views on iOS.

PADTiltViewController

Link to video: Youtube

Installation

PADTiltViewController is available on CocoaPods. Just add the following line to your project Podfile:

pod 'PADTiltViewController'

Alternatively, you can manually add the files into your Xcode project.

Usage

PADTiltViewController uses CoreMotion framework to detect tilt gesture.

Start by subclassing PADTiltCollectionViewController, PADTiltScrollViewController or PADTiltTableViewController based on your application design.

#import <PADTiltViewController/PADTiltViewController.h>

@interface PADTiltTableViewControllerExample : PADTiltTableViewController

@end

Motion manager

Your application should create only a single instance of the CMMotionManager class. Multiple instances of this class can affect the rate at which an application receives data from the accelerometer and gyroscope.

Set pad_motionManager property to reference this instance (ideally in viewDidLoad).

- (void)viewDidLoad {
  [super viewDidLoad];

  self.pad_motionManager = [(PADAppDelegate *)[[UIApplication sharedApplication] delegate] motionManager];
}

Scroll view

PADTiltScrollViewController requires you to manually provide an instance of UIScrollView, UITableView or UICollectionView and assign it to scrollView property. You can do this either programmatically or using storyboard/xib file.

- (void)viewDidLoad {
  [super viewDidLoad];

  self.scrollView = self.collectionView;
}

Tilt direction

Optionally you can also set the preferred tilt direction.

// Horizontal collection view
self.pad_tiltDirection = PADTiltDirectionHorizontal;

Start & Stop

Start tilt updates by calling pad_startReceivingTiltUpdates.

- (void)startReceivingTiltUpdates {
  [self pad_startReceivingTiltUpdates];

  // Custom logic goes here
}

Stop tilt updates by calling pad_stopReceivingTiltUpdates.

- (void)stopReceivingTiltUpdates {
  [self pad_stopReceivingTiltUpdates];

  // Custom logic goes here
}

There's also an example project. In the example, you can tilt vertical table views and a horizontal collection view.

Best practices

  • Due to the fact that motion sensors cause higher battery drain, always disable tilt when not needed.
  • Do not combine gestural with tilt driven scrolling.
  • Make users aware of the fact that tilt is enabled using a proper UI (you can take inspiration from the example project).

How it works

PADTiltViewController uses PADTiltAdditions category on UIViewController in conjunction with associated objects to extend the behavior of UIViewController, UICollectionViewController and UITableViewController.

Contributing

See the CONTRIBUTING.md file for how to help out.

License

PADTiltViewController is released under a MIT License. See LICENSE file for details.