|
// NINavigationBar.h |
|
@protocol ScheduleNavigationDelegate |
|
|
|
- (NSString *)getScheduleScreenIdentifier; |
|
|
|
@end |
|
|
|
@interface NINavigationBarSchedule : UINavigationBar |
|
|
|
@property (nonatomic, strong) id<ScheduleNavigationDelegate> scheduleDelegate; |
|
|
|
@end |
|
|
|
// NINavigationBar.m |
|
@interface NINavigationBarSchedule () |
|
|
|
@property (nonatomic, strong) NIScheduleNavigationDropdown *dropDown; |
|
|
|
@end |
|
|
|
@implementation NINavigationBarSchedule |
|
|
|
- (id)initWithCoder:(NSCoder *)aDecoder |
|
{ |
|
self = [super initWithCoder:aDecoder]; |
|
if (self) { |
|
[self addNavigationSlideDownGesture]; |
|
[self makeSlideDownView]; |
|
} |
|
return self; |
|
} |
|
|
|
- (void)addNavigationSlideDownGesture |
|
{ |
|
UITapGestureRecognizer *singleTap; |
|
singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)]; |
|
[singleTap setNumberOfTouchesRequired:1]; |
|
[singleTap setEnabled:YES]; |
|
[self addGestureRecognizer:singleTap]; |
|
} |
|
|
|
- (void)makeSlideDownView |
|
{ |
|
CGRect frame = CGRectMake(0, 0, 320, 144); |
|
frame.origin.y = CGRectGetMaxY(self.frame) - frame.size.height + 20; |
|
|
|
self.dropDown = [[NIScheduleNavigationDropdown alloc] initWithFrame:frame]; |
|
} |
|
|
|
- (void)didTap:(id)sender |
|
{ |
|
// find the subclassed UINavigationItem that has all the custom styles applied to it |
|
NINavigationItemSchedule *scheduleItem = nil; |
|
for (UINavigationItem *item in self.items) { |
|
if ([item isKindOfClass:[NINavigationItemSchedule class]]) { |
|
scheduleItem = (NINavigationItemSchedule *)item; |
|
break; |
|
} |
|
} |
|
|
|
// show or hide the dropdown |
|
CGFloat slideTime = 0.25f; |
|
if (self.dropDown.hidden) { |
|
[self slideNavigationMenuDownWithDuration:slideTime forNavigationItem:scheduleItem]; |
|
} else { |
|
[self slideNavigationMenuUpWithDuration:slideTime forNavigationItem:scheduleItem]; |
|
} |
|
} |
|
|
|
- (void)slideNavigationMenuDownWithDuration:(CGFloat)duration forNavigationItem:(NINavigationItemSchedule *)scheduleItem |
|
{ |
|
// flip the chevron arrow |
|
scheduleItem.titleView = [scheduleItem upChevronAttributedLabel]; |
|
|
|
self.dropDown.hidden = NO; |
|
[self.superview insertSubview:self.dropDown belowSubview:self]; |
|
[self.dropDown setHighlightedItem:[self.scheduleDelegate getScheduleScreenIdentifier]]; |
|
[UIView animateWithDuration:duration animations:^{ |
|
CGRect frame = self.dropDown.frame; |
|
frame.origin.y = CGRectGetMaxY(self.frame); |
|
self.dropDown.frame = frame; |
|
}]; |
|
} |
|
|
|
- (void)slideNavigationMenuUpWithDuration:(CGFloat)duration forNavigationItem:(NINavigationItemSchedule *)scheduleItem |
|
{ |
|
// flip the chevron arrow |
|
scheduleItem.titleView = [scheduleItem downChevronAttributedLabel]; |
|
|
|
[UIView animateWithDuration:duration animations:^{ |
|
CGRect frame = CGRectMake(0, 0, 320, 144); |
|
frame.origin.y = CGRectGetMaxY(self.frame) - frame.size.height; |
|
self.dropDown.frame = frame; |
|
} completion:^(BOOL finished) { |
|
self.dropDown.hidden = YES; |
|
}]; |
|
} |
|
|
|
@end |