一、手势
项目:0524GestureRecognizer
//总共有7种手势:点击、平移、清扫、捏合、边缘化入、旋转、长按
//所有手势的顶级父类:UIGestureRecognizer
二、UIMenuController
(一)项目:0524GestureRecognizer
- (void)viewDidLoad {
[super viewDidLoad];
//longPress 长按
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
[view addGestureRecognizer:longPress];
}
#pragma mark 长按事件
- (void)longPressAction:(UILongPressGestureRecognizer *)gesture{
//长按,和UIMenuController 弹出的copy粘贴进行组合使用
UIMenuController *menuCtr = [UIMenuController sharedMenuController];
UIMenuItem *item = [[UIMenuItem alloc]initWithTitle:@"自定义" action:@selector(action:)];
menuCtr.menuItems = @[item];
CGPoint point = [gesture locationInView:gesture.view];
[menuCtr setTargetRect:CGRectMake(point.x, point.y, 0, 0) inView:gesture.view];
[menuCtr setMenuVisible:YES animated:YES];
}
#pragma mark 如果想让menuCtr弹出,需要实现以下几个方法
- (BOOL)canBecomeFirstResponder{
return YES;
}
- (void)cut:(id)sender{
}
- (void)action:(UIMenuItem *)item{
}
(二)项目0527UITextView
#pragma mark (6)UITextView自定选择文字后的菜单
- (void)createSelectedStringMenu{
UIMenuItem *menuItem = [[UIMenuItem alloc]initWithTitle:@"分享到新浪微博" action:@selector(changeColor:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObject:menuItem]];
}
- (void)changeColor:(UIMenuItem *)sender{
NSLog(@"改变颜色");
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
if (action == @selector(changeColor:)) {
if (self.textView.selectedRange.length>0) {
return YES;
}
}
return NO;
}