Skip to content

Commit

Permalink
Add blooming from center
Browse files Browse the repository at this point in the history
change related methods and examples (both OC and Swift).
  • Loading branch information
thundertrick committed Sep 4, 2015
1 parent 8e68626 commit 287a6f4
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DCPathButton/Classes/DCPathButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ typedef NS_ENUM(NSUInteger, kDCPathButtonBloomDirection) {
kDCPathButtonBloomDirectionBottomRight = 6,
kDCPathButtonBloomDirectionRight = 7,
kDCPathButtonBloomDirectionTopRight = 8,

kDCPathButtonBloomDirectionCenter = 9,
};

@protocol DCPathButtonDelegate <NSObject>
Expand Down
26 changes: 21 additions & 5 deletions DCPathButton/Classes/DCPathButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (instancetype)initWithCenterImage:(UIImage *)centerImage
highlightedImage:(UIImage *)centerHighlightedImage {
return [self initWithButtonFrame:CGRectZero
centerImage:centerImage
highlightedImage:centerHighlightedImage];
highlightedImage:centerHighlightedImage];
}

- (instancetype)initWithButtonFrame:(CGRect)centerButtonFrame
Expand Down Expand Up @@ -181,7 +181,7 @@ - (void)configureSounds {
// Configure bloom sound
//
NSURL *bloomSoundURL = [NSURL fileURLWithPath:self.bloomSoundPath];

// Configure fold sound
//
NSURL *foldSoundURL = [NSURL fileURLWithPath:self.foldSoundPath];
Expand Down Expand Up @@ -273,6 +273,7 @@ - (CGPoint)createEndPointWithRadius:(CGFloat)itemExpandRadius

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf((angel + 1) * M_PI) * itemExpandRadius,
self.pathCenterButtonBloomCenter.y + sinf((angel + 1) * M_PI) * itemExpandRadius);

case kDCPathButtonBloomDirectionBottomLeft:

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf((angel + 0.25) * M_PI) * itemExpandRadius,
Expand Down Expand Up @@ -307,7 +308,12 @@ - (CGPoint)createEndPointWithRadius:(CGFloat)itemExpandRadius

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf((angel + 1.25) * M_PI) * itemExpandRadius,
self.pathCenterButtonBloomCenter.y + sinf((angel + 1.25) * M_PI) * itemExpandRadius);


case kDCPathButtonBloomDirectionCenter:

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf(angel * 2 * M_PI) * itemExpandRadius,
self.pathCenterButtonBloomCenter.y + sinf(angel * 2 * M_PI) * itemExpandRadius);

default:

NSAssert(self.bloomDirection, @"DCPathButtonError: An error occur when you configuring the bloom direction");
Expand All @@ -334,6 +340,9 @@ - (void)pathCenterButtonFold {
}

CGFloat itemGapAngel = self.bloomAngel / (self.itemButtons.count - 1) ;
if (self.bloomDirection == kDCPathButtonBloomDirectionCenter) {
itemGapAngel = self.bloomAngel / self.itemButtons.count;
}
CGFloat currentAngel = (180.0f - self. bloomAngel)/2.0f;

// Load item buttons from array
Expand Down Expand Up @@ -453,6 +462,10 @@ - (void)setBloomDirection:(kDCPathButtonBloomDirection)bloomDirection {

}

if (bloomDirection == kDCPathButtonBloomDirectionCenter) {
_bloomAngel = 360.0f;
}

}

- (void)pathCenterButtonBloom {
Expand Down Expand Up @@ -506,6 +519,9 @@ - (void)pathCenterButtonBloom {
// 5. Excute the bloom animation
//
CGFloat itemGapAngel = self.bloomAngel / (self.itemButtons.count - 1) ;
if (self.bloomDirection == kDCPathButtonBloomDirectionCenter) {
itemGapAngel = self.bloomAngel / self.itemButtons.count;
}
CGFloat currentAngel = (180.0f - self. bloomAngel)/2.0f;

for (int i = 0; i < self.itemButtons.count; i++) {
Expand All @@ -531,8 +547,8 @@ - (void)pathCenterButtonBloom {
CGPoint nearPoint = [self createEndPointWithRadius:self.bloomRadius - 5.0f andAngel:currentAngel/180.0f];

CAAnimationGroup *bloomAnimation = [self bloomAnimationWithEndPoint:endPoint
andFarPoint:farPoint
andNearPoint:nearPoint];
andFarPoint:farPoint
andNearPoint:nearPoint];

[pathItemButton.layer addAnimation:bloomAnimation
forKey:@"bloomAnimation"];
Expand Down
1 change: 1 addition & 0 deletions Example-Swift/DCPathButton/Classes/DCPathButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef NS_ENUM(NSUInteger, kDCPathButtonBloomDirection) {
kDCPathButtonBloomDirectionBottomRight = 6,
kDCPathButtonBloomDirectionRight = 7,
kDCPathButtonBloomDirectionTopRight = 8,
kDCPathButtonBloomDirectionCenter = 9,

};

Expand Down
26 changes: 21 additions & 5 deletions Example-Swift/DCPathButton/Classes/DCPathButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (instancetype)initWithCenterImage:(UIImage *)centerImage
highlightedImage:(UIImage *)centerHighlightedImage {
return [self initWithButtonFrame:CGRectZero
centerImage:centerImage
highlightedImage:centerHighlightedImage];
highlightedImage:centerHighlightedImage];
}

- (instancetype)initWithButtonFrame:(CGRect)centerButtonFrame
Expand Down Expand Up @@ -181,7 +181,7 @@ - (void)configureSounds {
// Configure bloom sound
//
NSURL *bloomSoundURL = [NSURL fileURLWithPath:self.bloomSoundPath];

// Configure fold sound
//
NSURL *foldSoundURL = [NSURL fileURLWithPath:self.foldSoundPath];
Expand Down Expand Up @@ -273,6 +273,7 @@ - (CGPoint)createEndPointWithRadius:(CGFloat)itemExpandRadius

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf((angel + 1) * M_PI) * itemExpandRadius,
self.pathCenterButtonBloomCenter.y + sinf((angel + 1) * M_PI) * itemExpandRadius);

case kDCPathButtonBloomDirectionBottomLeft:

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf((angel + 0.25) * M_PI) * itemExpandRadius,
Expand Down Expand Up @@ -307,7 +308,12 @@ - (CGPoint)createEndPointWithRadius:(CGFloat)itemExpandRadius

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf((angel + 1.25) * M_PI) * itemExpandRadius,
self.pathCenterButtonBloomCenter.y + sinf((angel + 1.25) * M_PI) * itemExpandRadius);


case kDCPathButtonBloomDirectionCenter:

return CGPointMake(self.pathCenterButtonBloomCenter.x + cosf(angel * 2 * M_PI) * itemExpandRadius,
self.pathCenterButtonBloomCenter.y + sinf(angel * 2 * M_PI) * itemExpandRadius);

default:

NSAssert(self.bloomDirection, @"DCPathButtonError: An error occur when you configuring the bloom direction");
Expand All @@ -334,6 +340,9 @@ - (void)pathCenterButtonFold {
}

CGFloat itemGapAngel = self.bloomAngel / (self.itemButtons.count - 1) ;
if (self.bloomDirection == kDCPathButtonBloomDirectionCenter) {
itemGapAngel = self.bloomAngel / self.itemButtons.count;
}
CGFloat currentAngel = (180.0f - self. bloomAngel)/2.0f;

// Load item buttons from array
Expand Down Expand Up @@ -453,6 +462,10 @@ - (void)setBloomDirection:(kDCPathButtonBloomDirection)bloomDirection {

}

if (bloomDirection == kDCPathButtonBloomDirectionCenter) {
_bloomAngel = 360.0f;
}

}

- (void)pathCenterButtonBloom {
Expand Down Expand Up @@ -506,6 +519,9 @@ - (void)pathCenterButtonBloom {
// 5. Excute the bloom animation
//
CGFloat itemGapAngel = self.bloomAngel / (self.itemButtons.count - 1) ;
if (self.bloomDirection == kDCPathButtonBloomDirectionCenter) {
itemGapAngel = self.bloomAngel / self.itemButtons.count;
}
CGFloat currentAngel = (180.0f - self. bloomAngel)/2.0f;

for (int i = 0; i < self.itemButtons.count; i++) {
Expand All @@ -531,8 +547,8 @@ - (void)pathCenterButtonBloom {
CGPoint nearPoint = [self createEndPointWithRadius:self.bloomRadius - 5.0f andAngel:currentAngel/180.0f];

CAAnimationGroup *bloomAnimation = [self bloomAnimationWithEndPoint:endPoint
andFarPoint:farPoint
andNearPoint:nearPoint];
andFarPoint:farPoint
andNearPoint:nearPoint];

[pathItemButton.layer addAnimation:bloomAnimation
forKey:@"bloomAnimation"];
Expand Down
4 changes: 3 additions & 1 deletion Example-Swift/Example-Swift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class ViewController: UIViewController, DCPathButtonDelegate {
dcPathButton = DCPathButton(centerImage: UIImage(named: "chooser-button-tab"), highlightedImage: UIImage(named: "chooser-button-tab-highlighted"))

dcPathButton.delegate = self
dcPathButton.dcButtonCenter = CGPointMake(self.view.bounds.width/2, self.view.bounds.height - 25.5)
dcPathButton.dcButtonCenter = self.view.center
dcPathButton.bloomDirection = kDCPathButtonBloomDirection.DCPathButtonBloomDirectionCenter
dcPathButton.bottomViewColor = UIColor.grayColor()
dcPathButton.allowSounds = true
dcPathButton.allowCenterButtonRotation = true
dcPathButton.bloomRadius = 105
Expand Down
9 changes: 6 additions & 3 deletions Example/Example/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ - (void)configureDCPathButton
//
dcPathButton.bloomRadius = 120.0f;



// Change the DCButton's center
//
dcPathButton.dcButtonCenter = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height - 25.5f);
dcPathButton.dcButtonCenter = self.view.center;
dcPathButton.bloomDirection = kDCPathButtonBloomDirectionCenter;

// Setting the DCButton appearance
//
Expand All @@ -82,8 +85,8 @@ - (void)configureDCPathButton

dcPathButton.bottomViewColor = [UIColor grayColor];

dcPathButton.bloomDirection = kDCPathButtonBloomDirectionTopRight;
dcPathButton.dcButtonCenter = CGPointMake(10 + dcPathButton.frame.size.width/2, self.view.frame.size.height - dcPathButton.frame.size.height/2 - 10);
// dcPathButton.bloomDirection = kDCPathButtonBloomDirectionTopRight;
// dcPathButton.dcButtonCenter = CGPointMake(10 + dcPathButton.frame.size.width/2, self.view.frame.size.height - dcPathButton.frame.size.height/2 - 10);

[self.view addSubview:dcPathButton];

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion Example/Pods/DCPathButton/DCPathButton/Classes/DCPathButton.m

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 287a6f4

Please sign in to comment.