Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions JSDropDownMenu/JSDropDownMenu.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@
@interface JSIndexPath : NSObject

@property (nonatomic, assign) NSInteger column;
// 0 左边 1 右边
@property (nonatomic, assign) NSInteger leftOrRight;
// 左边行
@property (nonatomic, assign) NSInteger leftRow;
// 右边行
@property (nonatomic, assign) NSInteger row;

- (instancetype)initWithColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow row:(NSInteger)row;
+ (instancetype)indexPathWithCol:(NSInteger)col leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow row:(NSInteger)row;

Expand Down Expand Up @@ -63,6 +59,9 @@
@protocol JSDropDownMenuDelegate <NSObject>
@optional
- (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath;

// 在菜单显示或隐藏时调用 (PS . 隐藏指再次点击相同menu时的隐藏,menu切换时不会触发隐藏,只会有是显示事件
- (void)menu:(JSDropDownMenu *)menu didShowMenu:(BOOL)show;
@end

#pragma mark - interface
Expand Down
237 changes: 154 additions & 83 deletions JSDropDownMenu/JSDropDownMenu.m
100644 → 100755

Large diffs are not rendered by default.

Empty file modified JSDropDownMenu/ico_make.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added JSDropDownMenuDemo/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
836CBA231ACEC8F6003FADBE /* TableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 836CBA221ACEC8F6003FADBE /* TableViewController.m */; };
D0EED8831A63CBC700EE7AFD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D0EED8821A63CBC700EE7AFD /* main.m */; };
D0EED8861A63CBC700EE7AFD /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D0EED8851A63CBC700EE7AFD /* AppDelegate.m */; };
D0EED8891A63CBC700EE7AFD /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0EED8881A63CBC700EE7AFD /* ViewController.m */; };
Expand All @@ -29,6 +30,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
836CBA211ACEC8F6003FADBE /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = "<group>"; };
836CBA221ACEC8F6003FADBE /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = "<group>"; };
D0EED87D1A63CBC700EE7AFD /* JSDropDownMenuDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JSDropDownMenuDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
D0EED8811A63CBC700EE7AFD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D0EED8821A63CBC700EE7AFD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -95,6 +98,8 @@
D0EED88D1A63CBC700EE7AFD /* Images.xcassets */,
D0EED88F1A63CBC700EE7AFD /* LaunchScreen.xib */,
D0EED8801A63CBC700EE7AFD /* Supporting Files */,
836CBA211ACEC8F6003FADBE /* TableViewController.h */,
836CBA221ACEC8F6003FADBE /* TableViewController.m */,
);
path = JSDropDownMenuDemo;
sourceTree = "<group>";
Expand Down Expand Up @@ -240,6 +245,7 @@
D0EED8891A63CBC700EE7AFD /* ViewController.m in Sources */,
D0EED8861A63CBC700EE7AFD /* AppDelegate.m in Sources */,
D0EED8A91A63CCB300EE7AFD /* JSDropDownMenu.m in Sources */,
836CBA231ACEC8F6003FADBE /* TableViewController.m in Sources */,
D0EED8831A63CBC700EE7AFD /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -431,6 +437,7 @@
D0EED8A21A63CBC700EE7AFD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
D0EED8A31A63CBC700EE7AFD /* Build configuration list for PBXNativeTarget "JSDropDownMenuDemoTests" */ = {
isa = XCConfigurationList;
Expand All @@ -439,6 +446,7 @@
D0EED8A51A63CBC700EE7AFD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
41 changes: 38 additions & 3 deletions JSDropDownMenuDemo/JSDropDownMenuDemo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="O62-XP-sGO">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ufC-wZ-h7g">
<objects>
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModuleProvider="" sceneMemberID="viewController">
<viewController id="vXZ-lx-hvc" customClass="ViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
Expand All @@ -20,6 +20,41 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="367" y="172"/>
</scene>
<!--Table View Controller-->
<scene sceneID="VHs-nU-Ht7">
<objects>
<tableViewController id="O62-XP-sGO" customClass="TableViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="qXa-75-Q1q">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="cell" textLabel="Sgq-r6-wys" style="IBUITableViewCellStyleDefault" id="7rF-27-yNR">
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="7rF-27-yNR" id="WKz-5V-m2I">
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Sgq-r6-wys">
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="O62-XP-sGO" id="QBP-9j-DoI"/>
<outlet property="delegate" destination="O62-XP-sGO" id="Pse-ys-QQ3"/>
</connections>
</tableView>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="kh1-J6-zHt" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="332" y="971"/>
</scene>
</scenes>
</document>
13 changes: 13 additions & 0 deletions JSDropDownMenuDemo/JSDropDownMenuDemo/TableViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TableViewController.h
// JSDropDownMenuDemo
//
// Created by HeQichang on 15/4/3.
// Copyright (c) 2015年 jsfu. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TableViewController : UITableViewController

@end
243 changes: 243 additions & 0 deletions JSDropDownMenuDemo/JSDropDownMenuDemo/TableViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
//
// TableViewController.m
// JSDropDownMenuDemo
//
// Created by HeQichang on 15/4/3.
// Copyright (c) 2015年 jsfu. All rights reserved.
//

#import "TableViewController.h"
#import "JSDropDownMenu.h"
@interface TableViewController ()<JSDropDownMenuDataSource,JSDropDownMenuDelegate>{
NSMutableArray *_mArray;
NSMutableArray *_data1;
NSMutableArray *_data2;
NSMutableArray *_data3;

NSInteger _currentData1Index;
NSInteger _currentData2Index;
NSInteger _currentData3Index;

NSInteger _currentData1SelectedIndex;
CGFloat prePosistionY;
JSDropDownMenu *menu;
}

@end

@implementation TableViewController

- (void)viewDidLoad {
[super viewDidLoad];

_mArray = [[NSMutableArray alloc] init];
for (int i = 0; i < 25; i++) {
[_mArray addObject:[self createRandomStr]];
}

// 指定默认选中
_currentData1Index = 1;
_currentData1SelectedIndex = 1;

NSArray *food = @[@"全部美食", @"火锅", @"川菜", @"西餐", @"自助餐"];
NSArray *travel = @[@"全部旅游", @"周边游", @"景点门票", @"国内游", @"境外游"];

_data1 = [NSMutableArray arrayWithObjects:@{@"title":@"美食", @"data":food}, @{@"title":@"旅游", @"data":travel}, nil];
_data2 = [NSMutableArray arrayWithObjects:@"智能排序", @"离我最近", @"评价最高", @"最新发布", @"人气最高", @"价格最低", @"价格最高", nil];
_data3 = [NSMutableArray arrayWithObjects:@"不限人数", @"单人餐", @"双人餐", @"3~4人餐", nil];

CGRect mainRect = self.tableView.frame;
menu = [[JSDropDownMenu alloc] initWithOrigin:CGPointMake(0, mainRect.size.height - 45) andHeight:45];
menu.indicatorColor = [UIColor colorWithRed:175.0f/255.0f green:175.0f/255.0f blue:175.0f/255.0f alpha:1.0];
menu.separatorColor = [UIColor colorWithRed:210.0f/255.0f green:210.0f/255.0f blue:210.0f/255.0f alpha:1.0];
menu.textColor = [UIColor colorWithRed:83.f/255.0f green:83.f/255.0f blue:83.f/255.0f alpha:1.0f];
menu.dataSource = self;
menu.delegate = self;

[self.view addSubview:menu];

}

- (NSString *)createRandomStr {
NSString *str = @"abcdefghijklmnopqrstuvwxyz";
NSInteger r = 1 + random()%15;
NSString *title = [str substringToIndex:r];
return title;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_mArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
cell.textLabel.text = _mArray[indexPath.row];
return cell;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat currentY = scrollView.contentOffset.y;


if (scrollView.isDragging && currentY > prePosistionY && currentY > 0) {
menu.hidden = YES;
} else if (scrollView.isDragging) {
menu.hidden = NO;
}
NSLog(@"%lf - %lf", prePosistionY, currentY);
CGRect menuRect = menu.frame;
menuRect.origin.y = menuRect.origin.y + (currentY - prePosistionY);
menu.frame = menuRect;
prePosistionY = currentY;
}

#pragma mark - JSDropDownMenuDataSource & JSDropDownMenuDelegate

- (NSInteger)numberOfColumnsInMenu:(JSDropDownMenu *)menu {

return 3;
}

-(BOOL)displayByCollectionViewInColumn:(NSInteger)column{

if (column==2) {

return YES;
}

return NO;
}

-(BOOL)haveRightTableViewInColumn:(NSInteger)column{

if (column==0) {
return YES;
}
return NO;
}

-(CGFloat)widthRatioOfLeftColumn:(NSInteger)column{

if (column==0) {
return 0.5;
}

return 1;
}

-(NSInteger)currentLeftSelectedRow:(NSInteger)column{

if (column==0) {

return _currentData1Index;

}
if (column==1) {

return _currentData2Index;
}

return 0;
}

- (NSInteger)menu:(JSDropDownMenu *)menu numberOfRowsInColumn:(NSInteger)column leftOrRight:(NSInteger)leftOrRight leftRow:(NSInteger)leftRow{

if (column==0) {
if (leftOrRight==0) {

return _data1.count;
} else{

NSDictionary *menuDic = [_data1 objectAtIndex:leftRow];
return [[menuDic objectForKey:@"data"] count];
}
} else if (column==1){

return _data2.count;

} else if (column==2){

return _data3.count;
}

return 0;
}

- (NSString *)menu:(JSDropDownMenu *)menu titleForColumn:(NSInteger)column{

switch (column) {
case 0: return [[_data1[_currentData1Index] objectForKey:@"data"] objectAtIndex:_currentData1SelectedIndex];
break;
case 1: return _data2[_currentData2Index];
break;
case 2: return _data3[_currentData3Index];
break;
default:
return nil;
break;
}
}

- (NSString *)menu:(JSDropDownMenu *)menu titleForRowAtIndexPath:(JSIndexPath *)indexPath {

if (indexPath.column==0) {
if (indexPath.leftOrRight==0) {
NSDictionary *menuDic = [_data1 objectAtIndex:indexPath.row];
return [menuDic objectForKey:@"title"];
} else{
NSInteger leftRow = indexPath.leftRow;
NSDictionary *menuDic = [_data1 objectAtIndex:leftRow];
return [[menuDic objectForKey:@"data"] objectAtIndex:indexPath.row];
}
} else if (indexPath.column==1) {

return _data2[indexPath.row];

} else {

return _data3[indexPath.row];
}
}

- (void)menu:(JSDropDownMenu *)menu didSelectRowAtIndexPath:(JSIndexPath *)indexPath {

if (indexPath.column == 0) {

if(indexPath.leftOrRight==0){

_currentData1Index = indexPath.row;

return;
}

} else if(indexPath.column == 1){

_currentData2Index = indexPath.row;

} else{

_currentData3Index = indexPath.row;
}
}

- (void)menu:(JSDropDownMenu *)menu didShowMenu:(BOOL)show {
if (show) {
self.tableView.scrollEnabled = NO;
} else {
self.tableView.scrollEnabled = YES;
}
}

@end
Loading