Skip to content

Commit 388b87b

Browse files
committedApr 7, 2013
Merge pull request weissi#30 from sptramer/feature-configurations
[FEATURE] Configurable snapping distance
2 parents 86a9c96 + ae8b1de commit 388b87b

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed
 

‎FRLayeredNavigationController/FRLayeredNavigationController.m

+7-4
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ + (BOOL)viewController:(FRLayerController *)vc xTranslation:(CGFloat)origXTransl
288288
const FRLayeredNavigationItem *navItem = vc.layeredNavigationItem;
289289
const CGPoint initPos = navItem.initialViewPosition;
290290

291+
CGRect f = vc.view.frame;
291292
if (bounded) {
292293
/* apply translation to fancy item position first and then apply to view */
293-
CGRect f = vc.view.frame;
294294
f.origin = navItem.currentViewPosition;
295295
f.origin.x += origXTranslation;
296296

@@ -301,7 +301,6 @@ + (BOOL)viewController:(FRLayerController *)vc xTranslation:(CGFloat)origXTransl
301301
vc.view.frame = f;
302302
navItem.currentViewPosition = f.origin;
303303
} else {
304-
CGRect f = vc.view.frame;
305304
CGFloat xTranslation;
306305
if (f.origin.x < initPos.x && origXTranslation < 0) {
307306
/* if view already left from left bound and still moving left, half moving speed */
@@ -348,7 +347,9 @@ - (void)viewControllersToSnappingPointsMethod:(SnappingPointsMethod)method
348347

349348
const CGFloat curDiff = myPos.x - last.layeredNavigationItem.currentViewPosition.x;
350349
const CGFloat initDiff = myInitPos.x - last.layeredNavigationItem.initialViewPosition.x;
351-
const CGFloat maxDiff = CGRectGetWidth(last.view.frame);
350+
const CGFloat maxDiff = ((last.layeredNavigationItem.snappingDistance >= 0) ?
351+
last.layeredNavigationItem.snappingDistance :
352+
CGRectGetWidth(last.view.frame));
352353

353354
if (xTranslation == 0 && (CGFloatNotEqual(curDiff, initDiff) && CGFloatNotEqual(curDiff, maxDiff))) {
354355
switch (method) {
@@ -411,7 +412,9 @@ - (void)moveViewControllersXTranslation:(CGFloat)xTranslationGesture
411412

412413
const CGPoint myPos = meNavItem.currentViewPosition;
413414
const CGPoint myInitPos = meNavItem.initialViewPosition;
414-
const CGFloat myWidth = CGRectGetWidth(me.view.frame);
415+
const CGFloat myWidth = ((meNavItem.snappingDistance >= 0) ?
416+
meNavItem.snappingDistance :
417+
CGRectGetWidth(me.view.frame));
415418
CGPoint myNewPos = myPos;
416419

417420
const CGPoint myOldPos = myPos;

‎FRLayeredNavigationController/FRLayeredNavigationItem.h

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
NSString *_title;
4444
UIView *_titleView;
4545
CGFloat _width;
46+
CGFloat _snappingDistance;
4647
CGFloat _nextItemDistance;
4748
BOOL _hasChrome;
4849
BOOL _hasBorder;
@@ -75,6 +76,12 @@
7576
*/
7677
@property (nonatomic, readwrite) CGFloat width;
7778

79+
/**
80+
* The maximum distance (when the child layer is being pulled out) to the next layer in points.
81+
* If this value is unset, it defaults to the layer's width.
82+
*/
83+
@property (nonatomic, readwrite) CGFloat snappingDistance;
84+
7885
/**
7986
* The minimal distance (when the child layer is as far on the left as possible) to the next layer in points.
8087
*/

‎FRLayeredNavigationController/FRLayeredNavigationItem.m

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ - (id)init
4646
if ((self = [super init])) {
4747
self->_width = -1;
4848
self->_nextItemDistance = -1;
49+
self->_snappingDistance = -1;
4950
self->_hasChrome = YES;
5051
self->_displayShadow = YES;
5152
self->_hasBorder = YES;
@@ -80,6 +81,7 @@ - (UIBarButtonItem *)rightBarButtonItem
8081
@synthesize title = _title;
8182
@synthesize titleView = _titleView;
8283
@synthesize width = _width;
84+
@synthesize snappingDistance = _snappingDistance;
8385
@synthesize nextItemDistance = _nextItemDistance;
8486
@synthesize hasChrome = _hasChrome;
8587
@synthesize hasBorder = _hasBorder;

0 commit comments

Comments
 (0)
Please sign in to comment.