//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. 【原创】Aspose.Words组件介绍及使用—基本介绍与DOM概述

           本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html 本博客其他.NET开源项目文章目录:http://www.cnbl ...

  2. 应用程序框架实战三十三:表现层及ASP.NET MVC介绍(二)

    最近的更新速度越来越慢,主要是项目上比较忙,封装EasyUi也要花很多时间.不过大家请放心,本系列不会半途夭折,并且代码干货也会持续更新.本文继续介绍表现层和Asp.net Mvc,我将在本篇讨论一些 ...

  3. Excel基础

    一.基础 一个Excel文档称为工作簿(workbook).一个工作簿中可以包含多个工作表(sheet) ctrl+向右箭头  查看最后一列 ctrl+向下箭头 查看最后一行 二.合并单元格 三.等高 ...

  4. machine learning基础与实践系列

    由于研究工作的需要,最近在看机器学习的一些基本的算法.选用的书是周志华的西瓜书--(<机器学习>周志华著)和<机器学习实战>,视频的话在看Coursera上Andrew Ng的 ...

  5. C#文件相同性判断

    在进行开发时,对文件进行上传和下载是较为普遍的行为,为了防止在文件操作过程中,出现同一文件多次操作,需要对文件进行相同性比较: 1.获取文件的绝对路径,针对window程序和web程序都可使用: // ...

  6. 【LeetCode】Reconstruct Itinerary(332)

    1. Description Given a list of airline tickets represented by pairs of departure and arrival airport ...

  7. maven pom中 设置远程仓库url

    <repositories> <!--<repository>--> <!--<id>spring-snapshots</id>--& ...

  8. 分享我基于NPOI+ExcelReport实现的导入与导出EXCEL类库:ExcelUtility (续篇)

    上周六我发表的文章<分享我基于NPOI+ExcelReport实现的导入与导出EXCEL类库:ExcelUtility>受到了大家的热烈支持与推荐,再此表示感谢,该ExcelUtility ...

  9. 五小步让VS Code支持AngularJS智能提示

    本文想通过配置VS Code来实现对AngularJS的智能提示.在一般的情况下对于在HTML页面是支持提示的.但是在js页面就不是很友好,它是记忆你之前的输入,要是之后有重复的输入,VS Code会 ...

  10. node.js操作mysql数据库之增删改查

    安装mysql模块 npm install mysql 数据库准备 mysql server所在的机器IP地址是192.168.0.108,登录账户就用root@123456 在mysql中创建tes ...