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 ...
随机推荐
- Android全屏(包含3种隐藏顶部状态栏及标题栏和一种隐藏Android 4.0平板底部状态栏的方法)
http://www.xuebuyuan.com/558284.html 方法一 public class MainActivity extends Activity { @Override prot ...
- 深入理解DOM节点类型第七篇——文档节点DOCUMENT
× 目录 [1]特征 [2]快捷访问 [3]文档写入 前面的话 文档节点document,隶属于表示浏览器的window对象,它表示网页页面,又被称为根节点.本文将详细介绍文档节点document的内 ...
- 【开源】OSharp3.3框架解说系列:开发计划与进度
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- Comet ASP.NET AJAX 示例
最近公司有个项目,里面要求要用到Comet技术,所以就到网上找了一下相关的资料和文章,发现有些人说用Ajax的长轮询比较好,后来就百度了一下,发现comet貌似就是通过ajax演变而来的,也就是com ...
- ViewStub的使用
ViewStub是一个不可见的.大小为0的控件,运行时ViewStub可以滞后加载.当ViewStub置为可见或者调用inflate()的时候,布局就会加载出来.用加载进来的布局取代ViewStub在 ...
- [翻译]利用顶点位移的VR畸变校正
文章英文原网址: http://www.gamasutra.com/blogs/BrianKehrer/20160125/264161/VR_Distortion_Correction_using_V ...
- 1Z0-053 争议题目解析134
1Z0-053 争议题目解析134 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 134.You are managing an Oracle Database 11g datab ...
- [linux]ssh(转载)
ssh登陆问题 SSH分客户端openssh-client和openssh-server 如果你只是想登陆别的机器的SSH只需要安装openssh-client(ubuntu有默认安装,如果没有则su ...
- Linux中读写权限
learn the auth of Linux. Generally, r-x w: write , modify and delete -2 r: read -4 x: execute ...
- Bootstrap Navbar应用及源码解析
目的: 用Bootstrap Navbar component 实现一个响应式导航 理解Bootstrap Navbar component是如何工作的(不包括collepse.js) 清楚自己添加一 ...