IOS界面弹窗显示多个按钮
2016-01-12 17:06
441 查看
在下面网站可以找到demo:
http://123.th7.cn/code/MLKMenuPopover_2415.html
主要内容:
增加 MLKMenuPopover 这样一个类。
这个类用来显示悬浮窗。
增加一个 协议。
协议里面有一下方法:
- (void)menuPopover:(MLKMenuPopover *)menuPopover didSelectMenuItemAtIndex:(NSInteger)selectedIndex;
用来提供 按下按键的操作。
这个类 提供四个方法
(id)initWithFrame:(CGRect)frame menuItems:(NSArray *)menuItems; 创建悬浮窗
(void)showInView:(UIView *)view; 显示悬浮窗
(void)dismissMenuPopover; 隐藏悬浮窗
(void)layoutUIForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@property(nonatomic,retain) NSArray *menuItems; 悬浮窗口的内容数组
//创建悬浮窗口 aMenuItems 这个参数是内容 frame是大小
- (id)initWithFrame:(CGRect)frame menuItems:(NSArray *)aMenuItems
{
self = [super initWithFrame:frame];
//
[self addSubview:menuItemsTableView];
}
////显示/隐藏图层
- (void)dismissMenuPopover
{
[self hide];
}
(void)showInView:(UIView *)view
{
self.containerButton.alpha = ZERO;
self.containerButton.frame = view.bounds;
[view addSubview:self.containerButton];
//用动画的效果
[UIView animateWithDuration:ANIMATION_DURATION
animations:^{
self.containerButton.alpha = ONE;
}
completion:^(BOOL finished) {}];
}
(void)hide
{
[UIView animateWithDuration:ANIMATION_DURATION
animations:^{
self.containerButton.alpha = ZERO;
}
completion:^(BOOL finished) {
[self.containerButton removeFromSuperview];
}];
}
在需要用到的地方
这个类必须遵守这个协议
- (void)viewDidLoad
{
[super viewDidLoad];
}
http://123.th7.cn/code/MLKMenuPopover_2415.html
主要内容:
增加 MLKMenuPopover 这样一个类。
这个类用来显示悬浮窗。
增加一个 协议。
协议里面有一下方法:
- (void)menuPopover:(MLKMenuPopover *)menuPopover didSelectMenuItemAtIndex:(NSInteger)selectedIndex;
用来提供 按下按键的操作。
这个类 提供四个方法
(id)initWithFrame:(CGRect)frame menuItems:(NSArray *)menuItems; 创建悬浮窗
(void)showInView:(UIView *)view; 显示悬浮窗
(void)dismissMenuPopover; 隐藏悬浮窗
(void)layoutUIForInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
@property(nonatomic,retain) NSArray *menuItems; 悬浮窗口的内容数组
//创建悬浮窗口 aMenuItems 这个参数是内容 frame是大小
- (id)initWithFrame:(CGRect)frame menuItems:(NSArray *)aMenuItems
{
self = [super initWithFrame:frame];
if (self) { self.menuItems = aMenuItems; // Adding Container Button which will take care of hiding menu when user taps outside of menu area self.containerButton = [[UIButton alloc] init];//创建一个按钮 [self.containerButton setBackgroundColor:CONTAINER_BG_COLOR]; [self.containerButton addTarget:self action:@selector(dismissMenuPopover) forControlEvents:UIControlEventTouchUpInside]; [self.containerButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin]; // Adding Menu Options Pointer 创建图标 UIImageView *menuPointerView = [[UIImageView alloc] initWithFrame:MENU_POINTER_RECT]; menuPointerView.image = [UIImage imageNamed:@"options_pointer"]; menuPointerView.tag = MENU_POINTER_TAG; [self.containerButton addSubview:menuPointerView]; // Adding menu Items table 创建表格 UITableView *menuItemsTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 11, frame.size.width, frame.size.height)]; menuItemsTableView.dataSource = self; menuItemsTableView.delegate = self; menuItemsTableView.separatorStyle = UITableViewCellSeparatorStyleNone; menuItemsTableView.scrollEnabled = NO; menuItemsTableView.backgroundColor = [UIColor clearColor]; menuItemsTableView.tag = MENU_TABLE_VIEW_TAG; UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Menu_PopOver_BG"]]; menuItemsTableView.backgroundView = bgView;
//
[self addSubview:menuItemsTableView];
[self.containerButton addSubview:self]; } return self;
}
////显示/隐藏图层
- (void)dismissMenuPopover
{
[self hide];
}
(void)showInView:(UIView *)view
{
self.containerButton.alpha = ZERO;
self.containerButton.frame = view.bounds;
[view addSubview:self.containerButton];
//用动画的效果
[UIView animateWithDuration:ANIMATION_DURATION
animations:^{
self.containerButton.alpha = ONE;
}
completion:^(BOOL finished) {}];
}
(void)hide
{
[UIView animateWithDuration:ANIMATION_DURATION
animations:^{
self.containerButton.alpha = ZERO;
}
completion:^(BOOL finished) {
[self.containerButton removeFromSuperview];
}];
}
在需要用到的地方
这个类必须遵守这个协议
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Menu Popover"; //填充这个 数组内容 self.menuItems = [NSArray arrayWithObjects:@"Menu Item 1", @"Menu Item 2", nil];
}
//创建这个图层 self.menuPopover = [[MLKMenuPopover alloc] initWithFrame:MENU_POPOVER_FRAME menuItems:self.menuItems]; self.menuPopover.menuPopoverDelegate = self; [self.menuPopover showInView:self.view];
相关文章推荐
- iOS项目groups和folder的区别(组和文件夹)
- iOS 类别和扩展(Categories和Extensions)
- 矩阵乘法 and BIOS loads MBR into 0x7C00?
- iOS NSPredicate的用法
- iOS关于model的两种写法
- iOS NSString的比较
- 【iOS开发】值对象篇----日期相关
- iOS判断是否静音状态
- iOS界面跳转方式
- <iOS>XML解析
- iOS拍照后存储照片到相册中
- ios tableview 插入删除
- iOS Run Loop
- iOS唯一标示符引导
- iOS引入小米push SDK出现duplicate symbol时的解决方法
- iOS NSUserDefaults使用详细解释
- Vmware虚拟机启动按F2无法进入BIOS的解决方法
- IOS内存警告处理
- <iOS>常见错误提示
- iOS开发63-__block 和 __weak的区别