一版确、手勢
項目:0524GestureRecognizer
//總共有7種手勢:點擊、平移燃少、清掃、捏合瞳氓、邊緣化入送粱、旋轉(zhuǎn)靴庆、長按
//所有手勢的頂級父類: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彈出炉抒,需要實現(xiàn)以下幾個方法
- (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;
}