Skip to content

Commit e6dbe1b

Browse files
committed
add supporting for custom destination coordinate
1 parent 5144a20 commit e6dbe1b

File tree

4 files changed

+61
-34
lines changed

4 files changed

+61
-34
lines changed

FancyTabBar.xcodeproj/project.pbxproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@
236236
attributes = {
237237
LastUpgradeCheck = 0510;
238238
TargetAttributes = {
239+
AB8F048819B6FEAB004CFDED = {
240+
DevelopmentTeam = 7H6KWF2CU7;
241+
};
239242
AB8F04A919B6FEAC004CFDED = {
240243
TestTargetID = AB8F048819B6FEAB004CFDED;
241244
};
@@ -417,6 +420,7 @@
417420
buildSettings = {
418421
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
419422
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
423+
DEVELOPMENT_TEAM = 7H6KWF2CU7;
420424
GCC_PRECOMPILE_PREFIX_HEADER = YES;
421425
GCC_PREFIX_HEADER = "FancyTabBar/FancyTabBar-Prefix.pch";
422426
INFOPLIST_FILE = "FancyTabBar/FancyTabBar-Info.plist";
@@ -430,6 +434,7 @@
430434
buildSettings = {
431435
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
432436
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
437+
DEVELOPMENT_TEAM = 7H6KWF2CU7;
433438
GCC_PRECOMPILE_PREFIX_HEADER = YES;
434439
GCC_PREFIX_HEADER = "FancyTabBar/FancyTabBar-Prefix.pch";
435440
INFOPLIST_FILE = "FancyTabBar/FancyTabBar-Info.plist";
@@ -497,6 +502,7 @@
497502
AB8F04BD19B6FEAC004CFDED /* Release */,
498503
);
499504
defaultConfigurationIsVisible = 0;
505+
defaultConfigurationName = Release;
500506
};
501507
AB8F04BE19B6FEAC004CFDED /* Build configuration list for PBXNativeTarget "FancyTabBarTests" */ = {
502508
isa = XCConfigurationList;
@@ -505,6 +511,7 @@
505511
AB8F04C019B6FEAC004CFDED /* Release */,
506512
);
507513
defaultConfigurationIsVisible = 0;
514+
defaultConfigurationName = Release;
508515
};
509516
/* End XCConfigurationList section */
510517
};

FancyTabBar/FancyTabBar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ typedef enum {
2424

2525
- (void) setUpChoices:(UIViewController*) parentViewController choices:(NSArray*) choices withMainButtonImage:(UIImage*)mainButtonImage;
2626
- (void) setUpChoices:(UIViewController*) parentViewController choices:(NSArray*) choices withMainButtonImage:(UIImage*)mainButtonImage andMainButtonCustomOrigin:(CGPoint)customOrigin;
27+
- (void) setUpChoices:(UIViewController*) parentViewController choices:(NSArray*) choices withMainButtonImage:(UIImage*)mainButtonImage andMainButtonCustomOrigin:(CGPoint)customOrigin choicesCoordinates:(NSArray*)choicesCoordinates;
28+
2729
@end

FancyTabBar/FancyTabBar.m

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ @interface FancyTabBar(){
3333
@property(nonatomic,strong) UIView *backgroundView;
3434
@property(nonatomic,strong) UIDynamicAnimator *dynamicsAnimator;
3535
@property(nonatomic,strong) UIDynamicBehavior *dynamicBehaviour;
36-
@property (assign, nonatomic) CGPoint mainBtnCustomOrigin;
36+
@property(assign, nonatomic) CGPoint mainBtnCustomOrigin;
37+
@property(nonatomic, copy) NSArray *choiceCoordinates;
3738

3839
@property(nonatomic,weak) UIViewController *parentViewController;
3940

@@ -79,6 +80,10 @@ - (void) setUpChoices:(UIViewController*) parentViewController choices:(NSArray*
7980
_mainBtnCustomOrigin=customOrigin;
8081
[self setUpChoices:parentViewController choices:choices withMainButtonImage:mainButtonImage];
8182
}
83+
- (void) setUpChoices:(UIViewController *)parentViewController choices:(NSArray *)choices withMainButtonImage:(UIImage *)mainButtonImage andMainButtonCustomOrigin:(CGPoint)customOrigin choicesCoordinates:(NSArray *)choicesCoordinates {
84+
self.choiceCoordinates = choicesCoordinates;
85+
[self setUpChoices:parentViewController choices:choices withMainButtonImage:mainButtonImage andMainButtonCustomOrigin:customOrigin];
86+
}
8287
- (void) setUpChoices:(UIViewController*) parentViewController choices:(NSArray*) choices withMainButtonImage:(UIImage*)mainButtonImage{
8388
_parentViewController = parentViewController;
8489
_choices = choices;
@@ -158,43 +163,49 @@ - (void) calculateExpandedCoordinates{
158163
[self addSubview:button];
159164
}
160165

161-
float plane = (parentWidth)-2*PADDING;
162-
float radius = plane/3;
163-
float xCentre = _mainButton.center.x;
164-
float yCentre = _mainButton.center.y;
165-
166-
167-
float x;
168-
float y;
169-
170-
float degrees = 180/(_choices.count-1);
171-
172-
for (int i=0; i < _choices.count; i++) {
173-
int tag = (i+1)*subviewTagConstant;
174-
Coordinate *coordinate = [[Coordinate alloc] init];
175-
float radian = (degrees*(i)*M_PI)/180;
176-
if (_currentDirectionToPopOptions==FancyTabBarItemsPop_Down) {
177-
//Pop Option Buttons Down
178-
radian = (degrees*(i)*M_PI)/-180;
179-
}
180-
float cosineRadian = cosf(radian);
181-
float sineRadian = sinf(radian);
182-
183-
float radiusLengthX = (radius * cosineRadian);
184-
float radiusLengthY = (radius * sineRadian);
166+
if (!self.choiceCoordinates && self.choiceCoordinates.count == _choices.count) {
167+
float plane = (parentWidth)-2*PADDING;
168+
float radius = plane/3;
169+
float xCentre = _mainButton.center.x;
170+
float yCentre = _mainButton.center.y;
185171

186-
x = xCentre + radiusLengthX;
187-
y = yCentre - radiusLengthY;
188172

189-
coordinate.x = [NSNumber numberWithInt:x];
190-
coordinate.y = [NSNumber numberWithInt:y];
173+
float x;
174+
float y;
191175

192-
coordinate.x = [NSNumber numberWithInt:x];
176+
float degrees = 180/(_choices.count-1);
193177

194-
coordinate.y = [NSNumber numberWithFloat:y];
195-
[_destinationCoordinateDictionary setObject:coordinate forKey:[NSNumber numberWithInt:tag]];
178+
for (int i=0; i < _choices.count; i++) {
179+
int tag = (i+1)*subviewTagConstant;
180+
Coordinate *coordinate = [[Coordinate alloc] init];
181+
float radian = (degrees*(i)*M_PI)/180;
182+
if (_currentDirectionToPopOptions==FancyTabBarItemsPop_Down) {
183+
//Pop Option Buttons Down
184+
radian = (degrees*(i)*M_PI)/-180;
185+
}
186+
float cosineRadian = cosf(radian);
187+
float sineRadian = sinf(radian);
188+
189+
float radiusLengthX = (radius * cosineRadian);
190+
float radiusLengthY = (radius * sineRadian);
191+
192+
x = xCentre + radiusLengthX;
193+
y = yCentre - radiusLengthY;
194+
195+
coordinate.x = [NSNumber numberWithInt:x];
196+
coordinate.y = [NSNumber numberWithInt:y];
197+
198+
coordinate.x = [NSNumber numberWithInt:x];
199+
200+
coordinate.y = [NSNumber numberWithFloat:y];
201+
[_destinationCoordinateDictionary setObject:coordinate forKey:[NSNumber numberWithInt:tag]];
202+
}
203+
} else {
204+
for (int i = 0; i < self.choiceCoordinates.count; i++) {
205+
int tag = (i + 1) * subviewTagConstant;
206+
[_destinationCoordinateDictionary setObject:self.choiceCoordinates[i] forKey:@(tag)];
207+
}
196208
}
197-
198209
}
199210

200211
#pragma mark - animation

FancyTabBar/ViewController.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#import "UIView+Screenshot.h"
1111
#import "UIImage+ImageEffects.h"
1212
#import "FancyTabBar.h"
13+
#import "Coordinate.h"
1314

1415
@interface ViewController ()<FancyTabBarDelegate>
1516

@@ -25,7 +26,13 @@ - (void)viewDidLoad
2526
[super viewDidLoad];
2627
// Do any additional setup after loading the view, typically from a nib.
2728
_fancyTabBar = [[FancyTabBar alloc]initWithFrame:self.view.bounds];
28-
[_fancyTabBar setUpChoices:self choices:@[@"gallery",@"dropbox",@"camera",@"draw"] withMainButtonImage:[UIImage imageNamed:@"main_button"]];
29+
Coordinate *c1 = [[Coordinate alloc] init];
30+
c1.y = @([UIScreen mainScreen].bounds.size.height - 88.0f - 109.0f);
31+
c1.x = @75.0f;
32+
Coordinate *c2 = [[Coordinate alloc] init];
33+
c2.y = c1.y;
34+
c2.x = @(88.0f + 50.0f + c1.x.doubleValue);
35+
[_fancyTabBar setUpChoices:self choices:@[@"camera",@"draw"] withMainButtonImage:[UIImage imageNamed:@"main_button"] andMainButtonCustomOrigin:CGPointMake(100.0f, 100.0f) choicesCoordinates:@[c1, c2]];
2936
// //Set Pop Items Direction
3037
// _fancyTabBar.currentDirectionToPopOptions=FancyTabBarItemsPop_Down;
3138
// //Custom Placement

0 commit comments

Comments
 (0)