Skip to content

Commit

Permalink
Change property expanding to expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
lvyzhu committed Feb 26, 2015
1 parent 2998b95 commit b6597d9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
Binary file not shown.
6 changes: 5 additions & 1 deletion AwesomeMenu/AwesomeMenu/AwesomeMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@property (nonatomic, copy) NSArray *menuItems;
@property (nonatomic, strong) AwesomeMenuItem *startButton;

@property (nonatomic, getter = isExpanding) BOOL expanding;
@property (nonatomic, getter = isExpanded) BOOL expanded;
@property (nonatomic, weak) id<AwesomeMenuDelegate> delegate;

@property (nonatomic, strong) UIImage *image;
Expand All @@ -42,6 +42,10 @@

- (AwesomeMenuItem *)menuItemAtIndex:(NSUInteger)index;

- (void)expand;

- (void)close;

@end

@protocol AwesomeMenuDelegate <NSObject>
Expand Down
44 changes: 30 additions & 14 deletions AwesomeMenu/AwesomeMenu/AwesomeMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ @implementation AwesomeMenu {
}

@synthesize nearRadius, endRadius, farRadius, timeOffset, rotateAngle, menuWholeAngle, startPoint, expandRotation, closeRotation, animationDuration, rotateAddButton;
@synthesize expanding = _expanding;
@synthesize expanded = _expanded;

#pragma mark - Initialization & Cleaning up

Expand Down Expand Up @@ -138,7 +138,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
}
// if the menu state is expanding, everywhere can be touch
// otherwise, only the add button are can be touch
if (YES == _expanding)
if (YES == [self isExpanded])
{
return YES;
}
Expand All @@ -150,7 +150,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
self.expanding = !self.isExpanding;
self.expanded = ![self isExpanded];
}

#pragma mark - AwesomeMenuItem delegates
Expand All @@ -159,7 +159,7 @@ - (void)AwesomeMenuItemTouchesBegan:(AwesomeMenuItem *)item
{
if (item == self.startButton)
{
self.expanding = !self.isExpanding;
self.expanded = ![self isExpanded];
}
}
- (void)AwesomeMenuItemTouchesEnd:(AwesomeMenuItem *)item
Expand All @@ -186,10 +186,10 @@ - (void)AwesomeMenuItemTouchesEnd:(AwesomeMenuItem *)item

otherItem.center = otherItem.startPoint;
}
_expanding = NO;
_expanded = NO;

// rotate start button
float angle = self.isExpanding ? -M_PI_4 : 0.0f;
float angle = [self isExpanded] ? -M_PI_4 : 0.0f;
[UIView animateWithDuration:animationDuration animations:^{
self.startButton.transform = CGAffineTransformMakeRotation(angle);
}];
Expand Down Expand Up @@ -229,6 +229,22 @@ - (AwesomeMenuItem *)menuItemAtIndex:(NSUInteger)index
return self.menuItems[index];
}

- (void)expand
{
if (_isAnimating || [self isExpanded]) {
return;
}
[self setExpanded:YES];
}

- (void)close
{
if (_isAnimating || ![self isExpanded]) {
return;
}
[self setExpanded:NO];
}

- (void)_setMenu {
NSUInteger count = [self.menuItems count];
for (int i = 0; i < count; i ++)
Expand All @@ -253,27 +269,27 @@ - (void)_setMenu {
}
}

- (BOOL)isExpanding
- (BOOL)isExpanded
{
return _expanding;
return _expanded;
}
- (void)setExpanding:(BOOL)expanding
- (void)setExpanded:(BOOL)expanded
{
if (expanding) {
if (expanded) {
[self _setMenu];
if(self.delegate && [self.delegate respondsToSelector:@selector(awesomeMenuWillAnimateOpen:)]){
[self.delegate awesomeMenuWillAnimateOpen:self];
}
}

_expanding = expanding;
_expanded = expanded;
if(self.delegate && [self.delegate respondsToSelector:@selector(awesomeMenuWillAnimateClose:)]){
[self.delegate awesomeMenuWillAnimateClose:self];
}

// rotate add button
if (self.rotateAddButton) {
float angle = self.isExpanding ? -M_PI_4 : 0.0f;
float angle = [self isExpanded] ? -M_PI_4 : 0.0f;
[UIView animateWithDuration:kAwesomeMenuStartMenuDefaultAnimationDuration animations:^{
self.startButton.transform = CGAffineTransformMakeRotation(angle);
}];
Expand All @@ -282,8 +298,8 @@ - (void)setExpanding:(BOOL)expanding
// expand or close animation
if (!_timer)
{
_flag = self.isExpanding ? 0 : ([self.menuItems count] - 1);
SEL selector = self.isExpanding ? @selector(_expand) : @selector(_close);
_flag = [self isExpanded] ? 0 : ([self.menuItems count] - 1);
SEL selector = [self isExpanded] ? @selector(_expand) : @selector(_close);

// Adding timer to runloop to make sure UI event won't block the timer from firing
_timer = [NSTimer timerWithTimeInterval:timeOffset target:self selector:selector userInfo:nil repeats:YES];
Expand Down

0 comments on commit b6597d9

Please sign in to comment.