UITableViewCell当手指经过它时,是否可以制作高光?不仅仅是当它按下它时,而是当手指已经在屏幕上滑动并在 tableviewcell 上运行时?我已经尝试了所有的手势识别器(包括UILongPressGestureRecognizer)并且没有任何运气。
2 回答
            1        
        
		
尝试使用此功能,它类似于评论中提到的问题中的那个:
(在您的视图控制器中)
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    //assuming UITableView named tableView
    UITableViewCell *tableViewCell;
    CGPoint touchedPoint = [[touches anyObject] locationInView:self.view];
    for (int C = 0; C < [tableView numberOfRowsInSection:0]; C++) {
        //this should loop through all cells in your tableview
        tableViewCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:C]];
        if (CGRectContainsPoint(tableViewCell.frame, touchedPoint)) {
            [tableViewCell setHighlighted:TRUE];
        }  
        else {
            [tableViewCell setHighlighted:FALSE];
        }
    }
}
于 2012-10-10T03:40:13.710   回答
    
    
            0        
        
		
在 cellForRowAtIndexPath 中:
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[cell.contentView addGestureRecognizer:recognizer];
然后...
- (void)handleSwipe:(id)sender
{
    UISwipeGestureRecognizer *recognizer = (UISwipeGestureRecognizer *)sender;
    UIView *contentView = [recognizer view];
    UITableViewCell *cell = (UITableViewCell*)[contentView superview];
    [cell setSelected:YES];
}
我刚刚对此进行了测试,它的工作原理与您正在寻找的完全一样。
编辑:如果我不着急,我会在类型转换之前进行一些反省。
于 2012-10-10T03:52:13.653   回答