美文网首页
长按 复制 删除

长按 复制 删除

作者: LH_0811 | 来源:发表于2016-07-20 15:55 被阅读54次
//长按 复制 删除
- (void) handleLongPress:(UILongPressGestureRecognizer *)longPressRecognizer
{
    NSLog(@"long press state:%d",longPressRecognizer.state);
    if (longPressRecognizer.state != UIGestureRecognizerStateBegan) {
        return;
    }
    
    selectReplyView.backgroundColor = [UIColor clearColor];;

    UIView *view = [longPressRecognizer view];
    selectReplyView = view;
    view.backgroundColor = [UIColor lightGrayColor];

    [self becomeFirstResponder];

    selectLabelTag = view.tag;
    
    CGPoint location = [longPressRecognizer locationInView:self.replyBg];

    CGRect  rect = view.bounds;
    rect.origin.y = location.y;
    //rect.origin.x = location.x;
    UIMenuController *menu = [UIMenuController sharedMenuController];
    [menu setTargetRect:rect inView:self.replyBg];
    
    
    NSString*uid = [[UserSingle defaultUser] userInfo].uid;
    NSArray *replyArray = [self.dataDic objectForKey:@"comment"];
    NSString*authorid = [[replyArray objectAtIndex:selectLabelTag] objectForKey:@"user_id"];
    //本人才能删除自己的回复
    if ([uid isEqualToString:authorid]) {
        UIMenuItem *item = [[UIMenuItem alloc] initWithTitle:@"删除"
                                                      action:@selector(deleteReplayPressed:)];
        menu.menuItems = @[item];

    }else{
        menu.menuItems = @[];
    }
    

    [menu setMenuVisible:YES animated:YES];
}

相关文章

网友评论

      本文标题:长按 复制 删除

      本文链接:https://www.haomeiwen.com/subject/kkbvjttx.html