A simple class that enables anything that can be scrolled to be scrolled by bumping the device in a certain direction. Inspired by Amazon's Fire Phone ability to scroll without dragging.
This class was designed to work with and tested on iOS 7.1, but it might quite well work with earlier versions also. It requires ARC.
To use class in an app, just drag the MSMotionScroller class files (demo files and assets are not needed) into your project and add the CoreMotion framework. You can use CocoaPods, too. Please refer to this website for more details.
First, create an internal variable inside the desired view controller.
MSMotionScroller *motionScroll;
On the viewDidLoad method, simply instanciate the internal variable and assign its delegate.
motionScroll = [[MSMotionScroller alloc]init];
motionScroll.delegate = self;
MSMotionScroller defines a simple delegate that is fired when a motion is captured, by implementing the didMeanToScroll:direction
method.
- (void)didMeanToScroll:(MSScrollMotionDirection)direction {
switch (direction) {
case MSScrollMotionDirectionUp:
// DID MEAN TO SCROLL UP
break;
case MSScrollMotionDirectionDown:
// DID MEAN TO SCROLL DOWN
break;
case MSScrollMotionDirectionLeft:
// DID MEAN TO SCROLL LEFT
break;
case MSScrollMotionDirectionRight:
// DID MEAN TO SCROLL RIGHT
break;
}
}
MSMotionScroller implements a property to define the bump sensibility, defaults to 0.25.
@property CGFloat sensibility;
Another property is used to pause the capture for bumps, if needed.
@property BOOL pause;
This class implements a delegate method that gets fired when a bump is detected.
- (void)didMeanToScroll:(MSScrollMotionDirection)direction;
Check out the provided example to see how MSMotionScroller is used to scroll a table view and open a sliding menu.
If you wish to contribute please feel free to contact me. I'd love have you onboard!