Skip to content

Commit

Permalink
调整参数默认值,适配各屏幕尺寸。
Browse files Browse the repository at this point in the history
  • Loading branch information
KongPro committed Nov 16, 2016
1 parent 29cd31e commit c2d6d32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion PopMenuTableView/MenuView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef void(^BackViewTapBlock)();
/* 隐藏菜单 */
+ (void)hidden;

/**移除菜单 */
/* 移除菜单 */
+ (void)clearMenu;

/**
Expand Down
16 changes: 10 additions & 6 deletions PopMenuTableView/MenuView.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define BACKVIEW_TAG 88888 // 背景遮罩view的tag
#define KRowHeight 40 // cell行高
#define KDefaultMaxValue 6 // 菜单项最大值
#define KNavigationBar_H 64 // 导航栏64
#define KIPhoneSE_ScreenW 375
#define KMargin 15

@interface MenuView () <UITableViewDataSource,UITableViewDelegate>
Expand Down Expand Up @@ -131,17 +133,19 @@ - (void)adjustFrameForMenu{

menuView.tableView.frame = rect; // 根据菜单项,调整菜单内tableView的大小
menuView.frame = frame; // 根据菜单项,调整菜单的整体frame

}


#pragma mark -- Create Menu
+ (MenuView *)createMenuWithFrame:(CGRect)frame target:(UIViewController *)target dataArray:(NSArray *)dataArray itemsClickBlock:(void (^)(NSString *, NSInteger))itemsClickBlock backViewTap:(void (^)())backViewTapBlock{

CGFloat width = [UIScreen mainScreen].bounds.size.width * 0.3;
CGFloat height = dataArray.count > 6 ? 6 * KRowHeight : dataArray.count * KRowHeight; // 40 -> tableView's RowHeight
CGRect rect = CGRectMake(frame.origin.x, frame.origin.y, width, height); // 菜单中tableView的frame
frame = CGRectMake(frame.origin.x, frame.origin.y, width, height + KMargin); // 菜单的整体frame
// 计算frame
CGFloat factor = [UIScreen mainScreen].bounds.size.width < KIPhoneSE_ScreenW ? 0.36 : 0.3; // 适配比例
CGFloat width = frame.size.width ? frame.size.width : [UIScreen mainScreen].bounds.size.width * factor;
CGFloat height = dataArray.count > KDefaultMaxValue ? KDefaultMaxValue * KRowHeight : dataArray.count * KRowHeight;
CGFloat x = frame.origin.x ? frame.origin.x : [UIScreen mainScreen].bounds.size.width - width - KMargin * 0.5;
CGFloat y = frame.origin.y ? frame.origin.y : KNavigationBar_H - KMargin * 0.5;
CGRect rect = CGRectMake(x, y, width, height); // 菜单中tableView的frame
frame = CGRectMake(x, y, width, height + KMargin); // 菜单的整体frame

MenuView *menuView = [[MenuView alloc] init];
menuView.tag = MENU_TAG;
Expand Down
7 changes: 2 additions & 5 deletions PopMenuTableView/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ - (void)viewDidLoad {
};
NSArray *dataArray = @[dict1,dict2,dict3];
_dataArray = dataArray;

CGFloat x = self.view.bounds.size.width / 3 * 2;
CGFloat y = 64 - 12;

__weak __typeof(&*self)weakSelf = self;
/**
* 创建menu
* 创建menu : frame传递nil,则取默认值
*/
[MenuView createMenuWithFrame:CGRectMake(x, y, 0, 0) target:self.navigationController dataArray:dataArray itemsClickBlock:^(NSString *str, NSInteger tag) {
[MenuView createMenuWithFrame:CGRectZero target:self.navigationController dataArray:dataArray itemsClickBlock:^(NSString *str, NSInteger tag) {
// do something
[weakSelf doSomething:(NSString *)str tag:(NSInteger)tag];

Expand Down

0 comments on commit c2d6d32

Please sign in to comment.