Navigation Menu

Skip to content

Commit

Permalink
when user taps on an item that's partially offscreen it now attempts …
Browse files Browse the repository at this point in the history
…to make the full text of that item visible
  • Loading branch information
barrettj committed Oct 17, 2011
1 parent f0c8da3 commit bebe075
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions LightMenuBar/LightMenuBar.h
Expand Up @@ -34,4 +34,6 @@ typedef enum {

- (void)setSelectedItemIndex:(NSUInteger)itemIndex animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate;

- (void)handleAutoScrolling:(BOOL)animated;

@end
12 changes: 8 additions & 4 deletions LightMenuBar/LightMenuBar.m
Expand Up @@ -29,9 +29,16 @@ - (void)setSelectedItemIndex:(NSUInteger)selectedItemIndex {
- (void)setSelectedItemIndex:(NSUInteger)itemIndex animated:(BOOL)animated notifyDelegate:(BOOL)notifyDelegate{
_menuBarView.selectedItemIndex = itemIndex;

[self handleAutoScrolling:animated];

if (_menuBarView.delegate && notifyDelegate)
[_menuBarView.delegate itemSelectedAtIndex:itemIndex inMenuBar:self];
}

- (void)handleAutoScrolling:(BOOL)animated {
[_menuBarView setNeedsDisplay];

CGFloat desiredX = [_menuBarView getCenterOfItemAtIndex:itemIndex] - (_scrollView.bounds.size.width / 2);
CGFloat desiredX = [_menuBarView getCenterOfItemAtIndex:_menuBarView.selectedItemIndex] - (_scrollView.bounds.size.width / 2);

if (desiredX < 0)
desiredX = 0;
Expand All @@ -43,9 +50,6 @@ - (void)setSelectedItemIndex:(NSUInteger)itemIndex animated:(BOOL)animated notif
if (!(_scrollView.bounds.size.width > _menuBarView.barLength)) {
[_scrollView setContentOffset:CGPointMake(desiredX, 0) animated:animated];
}

if (_menuBarView.delegate && notifyDelegate)
[_menuBarView.delegate itemSelectedAtIndex:itemIndex inMenuBar:self];
}

- (BOOL)bounces {
Expand Down
1 change: 1 addition & 0 deletions LightMenuBar/LightMenuBarView.m
Expand Up @@ -351,6 +351,7 @@ - (void)tapGesRecoDetected:(UITapGestureRecognizer *)gesReco {
else if (self.menuBar.barStyle == LightMenuBarStyleItem)
{
self.selectedItemIndex = activeIndex;
[_menuBar handleAutoScrolling:YES];
[self render];
}
}
Expand Down

0 comments on commit bebe075

Please sign in to comment.