//1:普通

//
//  ViewController.m
//  DemoTest

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
}

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

#pragma mark - menu
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self becomeFirstResponder];
    UIMenuController *menu = [UIMenuController sharedMenuController];
    [menu setTargetRect:CGRectMake(0, 0, 300, 400) inView:self.view];
    [menu setMenuVisible:YES animated:YES];
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", NSStringFromSelector(action));
    return YES;
    
}
/** 剪切 */
- (void)cut:(id)sender {
    [UIPasteboard generalPasteboard].string = @"cut";
    //置nil
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 拷贝 */
- (void)copy:(id)sender {
    [UIPasteboard generalPasteboard].string = @"copy";
    //不置nil
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 粘贴 */
- (void)paste:(id)sender {
//    NSString * tempStr = [UIPasteboard generalPasteboard].string;
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 选择 */
- (void)select:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 全选 */
- (void)selectAll:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 删除 */
- (void)delete:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 文本写作方向从左到右 */
- (void)makeTextWritingDirectionLeftToRight:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 文本写作方向从右到左 */
- (void)makeTextWritingDirectionRightToLeft:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 切换黑体 */
- (void)toggleBoldface:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 切换斜体 */
- (void)toggleItalics:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 切换下划线 */
- (void)toggleUnderline:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 增加尺寸 */
- (void)increaseSize:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
/** 减小尺寸 */
- (void)decreaseSize:(id)sender {
    NSLog(@"-=-=-=-=-=-=-=-==-=-==%@", sender);
}
//替换
//_promptForReplace:
//简<=>繁
//_transliterateChinese:
//B/U
//_showTextStyleOptions:
//查询
//_lookup:
//添加快捷方式
//_addShortcut:
//Speak
//_accessibilitySpeak:
//Speak语言选择
//_accessibilitySpeakLanguageSelection:
//Speak暂停
//_accessibilityPauseSpeaking:
//共享
//_share:

@end

//2:在tabelview

//
//  ViewController.m
//  DemoTest

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:self.tableView];
}

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

#pragma mark - tableView menu

- (UITableView *)tableView {
    if (!_tableView) {
        self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:(UITableViewStylePlain)];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor greenColor];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 33;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = @"LPC";
    cell.textLabel.userInteractionEnabled = YES;
    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressCellHandle:)];
    [cell.textLabel addGestureRecognizer:longPressGesture];
    return cell;
}
//1:长按cell弹出Menu菜单
///** 允许menu菜单 */
//- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
//    return YES;
//}
///** 每个cell Menu菜单 */
//- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
//    return YES;
//}
//2:添加长按手势
-(void)longPressCellHandle:(UILongPressGestureRecognizer *)gesture {
    [gesture.view becomeFirstResponder];
    UIMenuController *menuController = [UIMenuController sharedMenuController];
    [menuController setTargetRect:gesture.view.frame inView:gesture.view.superview];
    [menuController setMenuVisible:YES animated:YES];
}

-(void)menuCopyBtnPressed:(UIMenuItem *)menuItem {
    [UIPasteboard generalPasteboard].string = @"";
}

/** 按钮操作 */
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    if(action == @selector(copy:)) {
        [UIPasteboard generalPasteboard].string = @"copy";
    }
    if(action == @selector(cut:)) {
        [UIPasteboard generalPasteboard].string = @"cut";
        [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
    if(action == @selector(paste:)) {
        NSString *pasteString = [UIPasteboard generalPasteboard].string;
        [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    }
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

@end

iOS UIMenuController菜单的更多相关文章

  1. iOS筛选菜单、分段选择器、导航栏、悬浮窗、转场动画、启动视频等源码

    iOS精选源码 APP启动视频 自定义按钮,图片可调整图文间距SPButton 一款定制性极高的轮播图,可自定义轮播图Item的样式(或只... iOS 筛选菜单 分段选择器 仿微信导航栏的实现,让你 ...

  2. 实现ios常见菜单效果的思路

    眼下见过的实现边側菜单的效果.比較流行的有下面三种:(效果图) 1.菜单条覆盖在部分主视图上 附上实现该效果的一个不错的源代码地址: http://code4app.com/ios/RNFrosted ...

  3. iOS - UIMenuController

    前言 NS_CLASS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED @interface UIMenuController : NSObject 1.UIMenuCont ...

  4. ios官方菜单项目重点剖析附项目源码

    原版教程:https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift ...

  5. iOS关于菜单滚动视图实现

    菜单滚动视图也是在项目开发过程中比较常用到的功能,先直接看效果图 实现的效果如下: 当菜单个数的总长度超过一个屏宽度就计算每一个的文字宽度,若没有则只进行一个屏平分,点击菜单项时,滚动的视图位置会随着 ...

  6. iOS 横向菜单

    MKHorizMenu 源码地址 现在想要实现以下效果,其中“选时间”这部分是一个NavigationBar,“日期”是横向的菜单,“电影时段”是TableView. 比较难实现的是横向菜单,因为没有 ...

  7. HTML5_CSS3实现iOS Path菜单

    在线演示 本地下载

  8. IOS中的动画菜单

    SvpplyTable(可折叠可张开的菜单动画) 允许你简单地创建可折叠可张开的菜单动画效果,灵感来自于Svpply app.不同表格项目使用JSON定义,你可以定义每个菜单项和任何子菜单,为每个项目 ...

  9. iOS 消息推送原理

    一.消息推送原理: 在实现消息推送之前先提及几个于推送相关概念,如下图: 1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Prov ...

随机推荐

  1. ASP.NET Core的配置(3): 将配置绑定为对象[下篇]

    我们在<读取配置信息>通过实例的形式演示了如何利用Options模型以依赖注入的方式直接获取由指定配置节绑定生成的Options对象,我们再次回顾一下当初我们编写的程序.如下面的代码片段所 ...

  2. Android自定义spinner下拉框实现的实现

    一:前言 本人参考博客:http://blog.csdn.net/jdsjlzx/article/details/41316417 最近在弄一个下拉框,发现Android自带的很难实现我的功能,于是去 ...

  3. angularjs 锚点操作服务 $anchorScroll

    在普通的html网页中,我们可以通过在url后边添加  #elementid 的方式,将页面显示定位到某个元素,也就是锚点. 但是在angularjs应用的网页中,页面路由的写法是 #route/ro ...

  4. Web前端上万字的知识总结

    下面是自己学HTML+DIV+CSS+JS时的学习笔记,给大家分享以下,相互学习.大二时候寒假在家无聊的时候想做点事,总结了一下web前端基础的东西,下面的每个字都是自己手敲的. 1.<html ...

  5. Windows 搭建 .NET 跨平台环境并运行应用程序

    写在前面 阅读目录: Install .NET Version Manager (DNVM) Install .NET Core Execution Environment (DNX) Write t ...

  6. CocoaPods 安装 使用

    1.开启 terminal 2.移除现有 Ruby 默认源 $ gem sources --remove https://rubygems.org/ 3.使用新的源 $ gem sources -a ...

  7. 把《c++ primer》读薄(3-1 标准库string类型初探)

    督促读书,总结精华,提炼笔记,抛砖引玉,有不合适的地方,欢迎留言指正. 问题1:养成一个好习惯,在头文件中只定义确实需要的东西 using namespace std; //建议需要什么再using声 ...

  8. Oracle常用的SQL方法总结

    在项目中一般需要对一些数据进行处理,以下提供一些基本的SQL语句: 1.基于条件的插入和修改:需要在表中插入一条记录,插入前根据key标识判断.如果标识符不存在,则插入新纪录,如果标识符存在,则根据语 ...

  9. 用MVC做支付宝手机网页支付问题

    支付宝支付接口手机网页支付 从官网扒下来的demo阿里做得还是相当不错的,只要参数改正确了基本上都是能跑通,WebForm的没什么大问题,这次要讲的主要是几个要注意的问题,因为是用MVC来做. 1.要 ...

  10. SQL Server时间粒度系列----第7节日历数据表详解

    本文目录列表: 1.时间粒度有关描述 2.时间维度有关功能函数3.日历数据表 4.日历数据表数据填充 5.总结语 6.参考清单列表   时间粒度有关描述   将该系列涉及到的时间粒度以及分钟以下的粒度 ...