iOS UIMenuController菜单
//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菜单的更多相关文章
- iOS筛选菜单、分段选择器、导航栏、悬浮窗、转场动画、启动视频等源码
iOS精选源码 APP启动视频 自定义按钮,图片可调整图文间距SPButton 一款定制性极高的轮播图,可自定义轮播图Item的样式(或只... iOS 筛选菜单 分段选择器 仿微信导航栏的实现,让你 ...
- 实现ios常见菜单效果的思路
眼下见过的实现边側菜单的效果.比較流行的有下面三种:(效果图) 1.菜单条覆盖在部分主视图上 附上实现该效果的一个不错的源代码地址: http://code4app.com/ios/RNFrosted ...
- iOS - UIMenuController
前言 NS_CLASS_AVAILABLE_IOS(3_0) __TVOS_PROHIBITED @interface UIMenuController : NSObject 1.UIMenuCont ...
- ios官方菜单项目重点剖析附项目源码
原版教程:https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift ...
- iOS关于菜单滚动视图实现
菜单滚动视图也是在项目开发过程中比较常用到的功能,先直接看效果图 实现的效果如下: 当菜单个数的总长度超过一个屏宽度就计算每一个的文字宽度,若没有则只进行一个屏平分,点击菜单项时,滚动的视图位置会随着 ...
- iOS 横向菜单
MKHorizMenu 源码地址 现在想要实现以下效果,其中“选时间”这部分是一个NavigationBar,“日期”是横向的菜单,“电影时段”是TableView. 比较难实现的是横向菜单,因为没有 ...
- HTML5_CSS3实现iOS Path菜单
在线演示 本地下载
- IOS中的动画菜单
SvpplyTable(可折叠可张开的菜单动画) 允许你简单地创建可折叠可张开的菜单动画效果,灵感来自于Svpply app.不同表格项目使用JSON定义,你可以定义每个菜单项和任何子菜单,为每个项目 ...
- iOS 消息推送原理
一.消息推送原理: 在实现消息推送之前先提及几个于推送相关概念,如下图: 1. Provider:就是为指定IOS设备应用程序提供Push的服务器,(如果IOS设备的应用程序是客户端的话,那么Prov ...
随机推荐
- 深入学习jQuery事件对象
× 目录 [1]获取 [2]事件类型 [3]事件目标[4]当前元素[5]事件冒泡[6]默认行为[7]命名空间[8]返回值[9]键值 前面的话 在触发DOM上的某个事件时,会产生一个事件对象event, ...
- Util应用程序框架公共操作类(五):异常公共操作类
任何系统都需要处理错误,本文介绍的异常公共操作类,用于对业务上的错误进行简单支持. 对于刚刚接触.Net的新手,碰到错误的时候,一般喜欢通过返回bool值的方式指示是否执行成功. public boo ...
- Util应用程序框架公共操作类(二):数据类型转换公共操作类(源码篇)
上一篇介绍了数据类型转换的一些情况,可以看出,如果不进行封装,有可能导致比较混乱的代码.本文通过TDD方式把数据类型转换公共操作类开发出来,并提供源码下载. 我们在 应用程序框架实战十一:创建VS解决 ...
- C语言之链表
这两天在复习C语言的知识,为了给下个阶段学习OC做准备,以下的代码的编译运行环境是Xcode5.0版本,写篇博文把昨天复习的C语言有关链表的知识给大家分享一下,以下是小菜自己总结的内容,代码也是按照自 ...
- C# 打印PDF文件之使用不同打印机打印所有页面或部分页面
C# 打印PDF文件之使用不同打印机打印所有页面或部分页面 最近在逛国外各大编程社区论坛的时候,发现很多人都在问一个关于PDF文件打印的问题:打印时如何选择非默认打印机并设置打印页面的范围.而一般情况 ...
- 你不知道的HttpHandler相关知识
一.关于IHttpHandler.IsReusable 很多人不明白,这哥们到底干嘛的,估计是微软最初的一个想法--让一个对象可以一直不断地被重复使用 ,但这个想法不成熟,会带来很多隐藏问题,一个对象 ...
- 一步一步拆解一个简单的iOS轮播图(三图)
导言(可以不看): 不吹不黑,也许是东半球最简单的iOS轮播图拆分注释(讲解不敢当)了(tree new bee).(一句话包含两个人,你能猜到有谁吗?提示:一个在卖手机,一个最近在卖书)哈哈... ...
- Web内置对象 跨页面传值
内置对象: 1.QueryString - 地址栏数据拼接 get传值方式 格式:?key=value优点:简单好用,速度快,不消耗服务器内存. 缺点:只能传字符串,保密性不好,长度有限 Reques ...
- 小米网css3导航下拉菜单代码
效果:http://hovertree.com/texiao/css3/19/ 代码如下: <!doctype html> <!-- W3C规范 --> <html la ...
- C#~异步编程再续~async异步方法与同步方法的并行
返回目录 今天晚上没事写了个测试的代码,又看了看.net的并行编程,两个方法,一个是异步async修饰的,另一个是普通的方法,在控制台程序的Main方法里去调用这两个方法,会有什么结果呢? 首先我们看 ...