Skip to content

Commit

Permalink
Merge pull request pppoe#3 from barrettj/master
Browse files Browse the repository at this point in the history
"Tapping slightly offscreen item now scrolls that item to be fully visible" Thanks :]
  • Loading branch information
pppoe committed Oct 18, 2011
2 parents f0c8da3 + bebe075 commit 2f9ef8f
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 2f9ef8f

Please sign in to comment.