//MenuView.h

 

//

//  MenuView.h

//  RockPopMenu

//

//  Created by zhuang chaoxiao on 14-6-26.

//  Copyright (c) 2014年 zhuang chaoxiao. All rights reserved.

//

#import <UIKit/UIKit.h>

@protocol MenuViewDelegate

@optional

@end

@interface MenuView : UIView

{

NSArray * _itemArray;

UIView * _itemBackView;

}

@property(nonatomic,weak) id<MenuViewDelegate> delegate;

+(id)shareMenuView;

+(void)showPopView:(UIView *)parentView withRect:(CGRect)rect withMenuItem:(NSArray*)array;

@end

/////////////////////////////////////////////////////////////////////////////////////////////////

@interface MyMenuItem : NSObject

{

//NSString * _strTitle;

//UIImage * _iconImg;

}

-(void)performAction;

+(id)initMenuItemWithTitle:(NSString*)title withIcon:(UIImage*)img withTarget:(id)target withSelector:(SEL)selector;

@property(nonatomic,strong) NSString * strTitle;

@property(nonatomic,strong) UIImage * iconImg;

@property(nonatomic,weak) id target;

@property(nonatomic) SEL action;

@end

 

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//MenuView.m
 

//

//  MenuView.m

//  RockPopMenu

//

//  Created by zhuang chaoxiao on 14-6-26.

//  Copyright (c) 2014年 zhuang chaoxiao. All rights reserved.

//

#import "MenuView.h"

#define ITEM_MARGIN_X 5.0f

#define ITEM_MARGIN_Y 5.0f

#define ITEM_IMAGE_WIDTH 28.0f

#define ITEM_IMAGE_HEIGHT 28.0f

#define ITEM_TEXT_WIDHT 100.0f

#define ITEM_TEXT_HEIGHT 25.0f

#define ITEM_WIDTH 145.0f

#define ITEM_HEIGHT 40.0f

@implementation MyMenuItem

+(id)initMenuItemWithTitle:(NSString*)title withIcon:(UIImage*)img withTarget:(id)target withSelector:(SEL)selector

{

return [[MyMenuItem alloc]initWithTitle:title withIcon:img withTarget:target withSelector:selector];

}

-(void)performAction

{

if( _target && [_target respondsToSelector:_action] )

{

[_target performSelectorOnMainThread:_action withObject:self waitUntilDone:YES];

}

}

-(id)initWithTitle:(NSString*)title withIcon:(UIImage*)img withTarget:(id)target withSelector:(SEL)selector

{

self = [super init];

if(self)

{

_strTitle = title;

_iconImg = img;

_target = target;

_action = selector;

}

return self;

}

@end

////////////////////////////////////////////////////////////////////////////////////////////////////////

@implementation MenuView

- (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

// Initialization code

self.frame = [[UIScreen mainScreen] bounds];

}

return self;

}

-(CGRect)layoutMenuItem:(UIView * )parentView

{

CGRect rect;

CGFloat yPos = 0;

int btnTag = 0;

UIView * contentView = [[UIView alloc]initWithFrame:CGRectZero];

for( MyMenuItem * item in _itemArray )

{

UIButton * btnView = [[UIButton alloc]initWithFrame:CGRectZero];

btnView.frame = CGRectMake(0, yPos, ITEM_WIDTH, ITEM_HEIGHT);

[contentView addSubview:btnView];

if( item.iconImg )

{

UIImageView * imgView = [[UIImageView alloc]initWithImage:item.iconImg];

imgView.frame = CGRectMake(ITEM_MARGIN_X, ITEM_MARGIN_Y, ITEM_IMAGE_WIDTH, ITEM_IMAGE_HEIGHT);

[btnView addSubview:imgView];

}

UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(ITEM_MARGIN_X*2+ITEM_IMAGE_WIDTH, ITEM_MARGIN_Y, ITEM_TEXT_WIDHT, ITEM_TEXT_HEIGHT)];

lab.text = item.strTitle;

lab.textColor = [UIColor greenColor];

[btnView addSubview:lab];

btnView.tag = btnTag;

[btnView addTarget:self action:@selector(performAction:) forControlEvents:UIControlEventTouchUpInside];

++ btnTag;

yPos += ITEM_HEIGHT;

}

rect = CGRectMake(0, 0, ITEM_WIDTH, yPos);

contentView.frame = rect;

[parentView addSubview:contentView];

return rect;

}

-(void)performAction:(id)sender

{

UIButton *btn = (UIButton*)sender;

MyMenuItem * item = _itemArray[btn.tag];

[item performAction];

[self dismissPopView];

}

-(void)dismissPopView

{

[UIView animateWithDuration:0.5f animations:^(void){

self.alpha = 0.0f;

}completion:^(BOOL finished){

self.alpha = 1.0f;

[self removeFromSuperview];

}];

}

-(void)showPopView:(UIView *)parentView withRect:(CGRect)rect withMenuItem:(NSArray*)array

{

self.backgroundColor = [UIColor clearColor];

[parentView addSubview:self];

_itemArray = array;

_itemBackView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

_itemBackView.backgroundColor = [UIColor grayColor];

[self addSubview:_itemBackView];

CGRect frame = [self layoutMenuItem:_itemBackView];

_itemBackView.frame = CGRectMake(_itemBackView.frame.origin.x, _itemBackView.frame.origin.y, frame.size.width, frame.size.height);

_itemBackView.layer.cornerRadius = 10;

}

+(void)showPopView:(UIView *)parentView withRect:(CGRect)rect withMenuItem:(NSArray*)array

{

[[self shareMenuView] showPopView:parentView withRect:rect withMenuItem:array];

}

+(id)shareMenuView

{

static MenuView * menu;

static dispatch_once_t once;

dispatch_once(&once,^{

menu = [[MenuView alloc]init];

});

return menu;

}

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect

{

// Drawing code

}

*/

@end

////////////////////////////////////////////////////////////////////////////////////////////

//调用

-(void)click

{

NSLog(@"click");

NSArray * arr= @[

[MyMenuItem initMenuItemWithTitle:@"点击查看详情" withIcon:[UIImage imageNamed:@"home_icon"] withTarget:self withSelector:(@selector(action1))],

[MyMenuItem initMenuItemWithTitle:@"明日天气预报" withIcon:[UIImage imageNamed:@"home_icon"] withTarget:self withSelector:(@selector(action2))],

[MyMenuItem initMenuItemWithTitle:@"中国人民银行" withIcon:[UIImage imageNamed:@"home_icon"] withTarget:self withSelector:(@selector(action1))],

];

[MenuView showPopView:self.view withRect:CGRectZero withMenuItem:arr];

}

-(void)action1

{

NSLog(@"action1");

}

-(void)action2

{

NSLog(@"action2");

}

本文转自  张江论坛 http://www.999dh.net/home.php?mod=space&uid=1&do=blog&id=205 转自请标注,谢谢~~~

IOS 弹出式 POPMenuView的更多相关文章

  1. web全栈开发之网站开发二(弹出式登录注册框前端实现-类腾讯)

    这次给大家分享的是目前很多网站中流行的弹出式登录框,如下面的腾讯网登录界面,采用弹出式登录的好处是大大提升了网站的用户体验和交互性,用户不用重新跳转到指定的页面就能登录,非常方便 先来个演示地址 要实 ...

  2. web开发实战--弹出式富文本编辑器的实现思路和踩过的坑

    前言: 和弟弟合作, 一起整了个智慧屋的小web站点, 里面包含了很多经典的智力和推理题. 其实该站点从技术层面来分析的话, 也算一个信息发布站点. 因此在该网站的后台运营中, 富文本的编辑器显得尤为 ...

  3. IOS弹出视图 LewPopupViewController

    LewPopupViewController是一款IOS弹出视图软件.iOS 下的弹出视图.支持iPhone/iPad. 软件截图 使用方法 弹出视图 1 2 3 4 5 PopupView *vie ...

  4. asp.net 弹出式日历控件 选择日期 Calendar控件

    原文地址:asp.net 弹出式日历控件 选择日期 Calendar控件 作者:逸苡 html代码: <%@ Page Language="C#" CodeFile=&quo ...

  5. PropertyGrid—为复杂属性提供下拉式编辑框和弹出式编辑框

    零.引言 PropertyGrid中我们经常看到一些下拉式的编辑方式(Color属性)和弹出式编辑框(字体),这些都是为一些复杂的属性提供的编辑方式,本文主要说明如何实现这样的编辑方式. 一.为属性提 ...

  6. ZH奶酪:Ionic中(弹出式窗口)的$ionicModal使用方法

    Ionic中[弹出式窗口]有两种(如下图所示),$ionicModal和$ionicPopup; $ionicModal是完整的页面: $ionicPopup是(Dialog)对话框样式的,直接用Ja ...

  7. php弹出式登录窗口并获得登录后返回值

    一款bootstrap样式结合php制作的弹出式登录窗口,输入用户名和密码后,ajax传参给后台,并获得登录后返回值. hwLayer+ajax弹出登录框 $(function() { $('#for ...

  8. 让小区运营再智能一点,EasyRadius正式向WayOs用户提供到期弹出式提示充值页面

    其实一直没向用户提供到期弹出式页面,主要是给VIP群的用户一点优越感,随着这次EasyRadius的更新,海哥就免费向普通easyRadius用户提供这两个模板下载. 有些人会问,什么样的模板.有什么 ...

  9. Operating System-Thread(5)弹出式线程&&使单线程代码多线程化会产生那些问题

    本文主要内容 弹出式线程(Pop-up threads) 使单线程代码多线程化会产生那些问题 一.弹出式线程(Pop-up threads) 以在一个http到达之后一个Service的处理为例子来介 ...

随机推荐

  1. Biba模型简介

    上周上信息安全的课,老师留了个Biba模型的作业.自己看书了解了一下,记录如下. 参考资料:石文昌<信息系统安全概论第2版> ISBN:978-7-121-22143-9 Biba模型是毕 ...

  2. linux下用非root用户重启导致ssh无法连接的问题

    问题描述 安装好了centOS服务器,一直用Secure CRT工具通过ssh服务来远程连接linux,很方便的进行各种操作.今天偶然尝试了一下在非root的一般用户下执行重启服务器的命令,发现一般用 ...

  3. 毕向东JAVA视频讲解笔记(前三课)

    1,定义一个类,因为java程序都定义类中,java程序都是以类的形式存在的,类的形式其实就是一个字节码文件最终体现. 2,定义一个主函数.为了让该类可以独立运行. 3,因为演示hello world ...

  4. Windows基于Apache的svn服务器配置

    参照 http://bbs.iusesvn.com/thread-158-1-1.html文章,经过svn的洗刷,终于把它配置成功,现在把我所配置的方法,记录下来,以供其他有需要的朋友参考,需要改进的 ...

  5. WCF入门(十一)---WCF安全

    一个强大的WCF服务安全系统,拥有两种安全模式或级别预期的客户端可以访问的服务.这是常见的分布式事务的安全威胁正在放缓,在很大程度上由WCF决定. 关键的安全功能 WCF服务有四个主要的安全功能,如下 ...

  6. 多线程进行n皇后计算

    在浏览zhihu的时候, 看到了这个问题:Linux c++服务器端这条线怎么走? http://www.zhihu.com/question/22608820 , 其中排第一的答案说的很不错.针对他 ...

  7. Support Library官方教程(2)各支援包的特性详介(含表)*

    快速阅读 包名  作用  位置 是否有资源 v4 提供了最多的api <sdk>/extras/android/support/v4/ y Multidex 把DEX文件生成apk < ...

  8. [UESTC1059]秋实大哥与小朋友(线段树, 离散化)

    题目链接:http://acm.uestc.edu.cn/#/problem/show/1059 普通线段树+离散化,关键是……离散化后建树和查询都要按照基本法!!!RE了不知道多少次………………我真 ...

  9. JasperReports+iReport在eclipse中的使用

    转载:http://blog.csdn.net/daming924/article/details/7402295 一.介绍1)它可以PDF,HTML,XML等多种形式产生报表或动态报表,在新版本还支 ...

  10. Codeforces Round #206 (Div. 1)B(记忆化)

    这题刚开始理解错题意了 以为只能往右和下走 这题挺好的 看题解看了N久啊 二维的DP 第一维表示走到第几步 可以画一个正方形 以左上角斜着划线 第i步走的点只能是第i条线上的点 而dp的第二维 就表示 ...