UIMenuController,弹出菜单

@implementation DragView
{
    CGPoint startLocation;
    CGFloat rotation;
}
-(instancetype)initWithImage:(UIImage *)anImage
{
    self=[super initWithImage:anImage];
    rotation=0.0f;
    if ( self) {
        self.userInteractionEnabled=YES;
        长按手势识别器
        UILongPressGestureRecognizer *pressGesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
        [self addGestureRecognizer:pressGesture];
    }
    return self;
}
只有成为第一响应者时menu才会弹出
-(BOOL)canBecomeFirstResponder
{
    return YES;
}

-(void)handleLongPress:(UILongPressGestureRecognizer *)uilpgr
{
    if (![self becomeFirstResponder]) {
        NSLog(@"Could not become first responder");
        return;
    }
    UIMenuController *menu=[UIMenuController sharedMenuController];
    UIMenuItem *pop=[[UIMenuItem alloc]initWithTitle:@"Pop" action:@selector(popSelf)];
    UIMenuItem *rotate=[[UIMenuItem alloc]initWithTitle:@"Rotation" action:@selector(rotationSelf)];
    UIMenuItem *ghost=[[UIMenuItem alloc]initWithTitle:@"Ghost" action:@selector(ghostSelf)];
    类似于UIBarButtonItem,实例化每个UIMenuItem,然后添加到menuItems中,menuItems是个数组。
    menu.menuItems=@[pop,rotate,ghost];
   
    [menu setTargetRect:self.bounds inView:self];
    这里是这只箭头方向UIMenuControllerArrowDown就是这样
UIMenuControllerArrowUp就是这样同理还有left和right

menu.arrowDirection=UIMenuControllerArrowDown;
    调用update方法才能使我们对菜单所做的修改生效
    [menu update];
    将菜单设为可见就可以了
    [menu setMenuVisible:YES];
}

- (void)popSelf
{
    [UIView animateWithDuration:0.25f animations:^(){self.transform = CGAffineTransformMakeScale(1.5f, 1.5f);} completion:^(BOOL Done){
        [UIView animateWithDuration:0.25 animations:^(){self.transform=CGAffineTransformIdentity;}] ;}];
}

- (void)rotationSelf
{
    [UIView animateWithDuration:0.25f animations:^(){self.transform = CGAffineTransformMakeRotation(rotation+M_PI * 0.5);} completion:^(BOOL done){
        rotation=M_PI*0.5+rotation;}];
}

- (void)ghostSelf
{
    [UIView animateWithDuration:1.25f animations:^(){self.alpha = 0.0f;} completion:^(BOOL done){
        [UIView animateWithDuration:1.25f animations:^(){} completion:^(BOOL done){
            [UIView animateWithDuration:0.5f animations:^(){self.alpha = 1.0f;}];
        }];
    }];
}

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    startLocation = [[touches anyObject] locationInView:self];
    [self.superview bringSubviewToFront:self];
}

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    CGPoint pt = [[touches anyObject] locationInView:self];
    float dx = pt.x - startLocation.x;
    float dy = pt.y - startLocation.y;
    CGPoint newcenter = CGPointMake(self.center.x + dx, self.center.y + dy);
    
    self.center = newcenter;
}

@end

iOS 弹出菜单UIMenuController的基本使用的更多相关文章

  1. IOS 弹出菜单的动态效果

    效果1.点击按钮上浮 2.点击按钮下沉 3.点击按钮下拉展示 4.点击按钮向上收缩 5.左右如是说 关键是改变视图的大小位置的时机正确与否 eg1.1.点击按钮下沉消失 已知myView.frame= ...

  2. iOS如何禁用长按页面弹出菜单

    iOS如何禁止用户长按页面导致弹出菜单? 给元素设置样式: -webkit-touch-callout:none; 补充:同样适用于图片如果想禁止用户保存或者复制等

  3. iOS开发——动画篇Swift篇&炫酷弹出菜单

    炫酷弹出菜单   这个是一个第三方按钮菜单组件,原版是使用Objective-C编写的名为AwesomeMenu的组件,地址是:https://github.com/levey/AwesomeMenu ...

  4. IOS实现弹出菜单效果MenuViewController(背景 景深 弹出菜单)

    在写项目时,要实现一个从下移上来的一个弹出菜单,并且背景变深的这么一个效果,在此分享给大家. 主要说一下思路及一些核心代码贴出来,要想下载源码, 请到:http://download.csdn.net ...

  5. 向上弹出菜单jQuery插件

    插件名:柯乐义英文名:Keleyijs文件名称:jquery.keleyi.js插件功能:该插件可以让你轻易地在页面上构建一个向上弹出的二级菜单. 示例查看:http://keleyi.com/kel ...

  6. html5手机端遮罩弹出菜单代码

    效果体验:http://hovertree.com/texiao/html5/17/ 效果图: 代码如下: <!doctype html> <html lang="zh&q ...

  7. DIV+CSS制作二级横向弹出菜单,略简单

    没有使用JavaScript控制二级菜单的显示,结果如上图所示. 代码如下: <!DOCTYPE html> <html> <head> <meta char ...

  8. vc++ 如何添加右键弹出菜单

    一.创建新工程 二.编辑菜单资源 1.添加菜单 按"Ctrl+R",双击"Menu"图标 2.于菜单编辑器内编辑菜单 四.添加代码(红色部分) void CCM ...

  9. 创建 iPhone/iOS8 弹出菜单(窗口)

    基本步骤 添加视图:主视图与弹出视图 关联视图 配置弹出视图 编码实现:弹出菜单样式及控制器委托 override func prepareForSegue(segue: UIStoryboardSe ...

随机推荐

  1. mysql存储过程实例,查询多参数赋值

    drop procedure if exists p_for_create_customer; create procedure p_for_create_customer()begin declar ...

  2. Deep Learning.ai学习笔记_第一门课_神经网络和深度学习

    目录 前言 第一周(深度学习引言) 第二周(神经网络的编程基础) 第三周(浅层神经网络) 第四周(深层神经网络) 前言 目标: 掌握神经网络的基本概念, 学习如何建立神经网络(包含一个深度神经网络), ...

  3. 从MySQL全库备份中恢复某个库和某张表

    在Mysqldump官方工具中,如何只恢复某个库呢? 全库备份 [root@HE1 ~]# mysqldump -uroot -p --single-transaction -A --master-d ...

  4. Mac下的Chrome或Safari访问跨域设置,MBP上使用模拟器Simulator.app或iphone+Safari调试网页

    Mac下的Chrome或Safari访问跨域设置: mac下终端启动Chrome $ open -a Google\ Chrome --args --disable-web-security 或 /A ...

  5. exp导出数据时丢表

    友军发来消息,说使用exp导出某个schema的数据的时候,发现有些表没有导出来.因为一直没有使用exp的习惯,就使用exp\expdp再次导出一次,分析二者的日志,发现exp的确有些表没有导出. 问 ...

  6. Python之多线程和多进程

    一.多线程 1.顺序执行单个线程,注意要顺序执行的话,需要用join. #coding=utf-8 from threading import Thread import time def my_co ...

  7. 安装最新版RabbitMQ v3.7.13 以及基本配置

    之前用的老版本,新项目新气象,RabbitMQ也用最新版吧 首先打开官网:http://www.rabbitmq.com/install-rpm.html 先到右侧导航栏来看一下 : 第一个红框是指的 ...

  8. 利用SEH防范BP(int 3)断点

    利用SEH技术实现反跟踪,这个方法比单纯用判断API函数第一个字节是否为断点更加有效,可以防止在API函数内部的多处地址设置断点 通过int 3指令故意产生一个异常,从而让系统转入自己的异常处理函数, ...

  9. RChain的跨分片交易算法

    跨分片交易是一个难题,但是遗憾的是业界已经有一个项目RChain解决了这个问题. 分片方式有很多种,最难的是状态分片,什么是状态分片呢?把以太坊比作银行的话,状态指的是银行账户的当前余额.那状态分片就 ...

  10. HDFS: The short-circuit local reads feature cannot be used

    问题: method:org.apache.hadoop.hdfs.DomainSocketFactory.<init>(DomainSocketFactory.java:69) The ...