Snap2me helps you add the snap feature to your views. Your views need some guidance when users drag and drop things in it. Snap2me helps you implement these line guides into any view and its subviews are snapped once they are captured in a threshold.
To run the example project, open up a terminal screen and copy paste the code below:
pod try 'Snap2me'
Put two views in a view controller, then you can bind viewToSnapInStoryBoard
by dragging property, right in the Xcode.
You can set snapping lines just like the following.
draggingView.axisPercentages = [
GuideLine.AxisPercentage(axis: .vertical, percentage: 0.5),
GuideLine.AxisPercentage(axis: .horizontal, percentage: 0.5),
GuideLine.AxisPercentage(axis: .horizontal, percentage: 0.1),
GuideLine.AxisPercentage(axis: .vertical, percentage: 0.1),
GuideLine.AxisPercentage(axis: .horizontal, percentage: 0.9),
GuideLine.AxisPercentage(axis: .vertical, percentage: 0.9)
]
draggableView.settings = GuideLine.Settings(
lineColor: UIColor.red,
lineWidth: 4,
shadowColor: UIColor.brown,
flushesInitially: true,
threshold: 15
)
Snap2me is available through CocoaPods. To install it, add the following line to your Podfile
:
pod 'Snap2me'
- Clean, easy to comprehend swift implementation, subclass the
Snap2meView
and enjoy dragging - Storyboard implementation
- Programmatic implementation
- Percent driven guide line distances
- Constant guide line distances
- Orientation handling
- Top, bottom, left, right snaps
- IBDesignables and IBInspectibles for
Snap2meView
- Wider test coverage
To run the tests simply select test target and select Snap2me_Example
as the host application. This is caused by an issue between Cocoapods and modern Xcode versions.
- iOS 9.0+
- Xcode 8.0+
- Swift 4.0+
Connected2.me / Erk Ekin @erkekin
IBDesignable and IBInspectible for guide lines, constant line distance accompanying to percentage, top, bottom, left and right snaps, support for rotaion change are considered to be improved, please contribute!
Snap2me is available under the MIT license. See the LICENSE file for more info.