2012-03-09 116 views
3

我有一個UITableView和其UITableViewCell了,我就是增加了UILongPressGestureRecognizer這樣的:的UITableViewCell閃爍上長按

// Setup Event-Handling 
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleTableViewCellLongPress:)]; 

[cell addGestureRecognizer:longPress]; 

[longPress setDelegate:self]; 

我想在小區當事件被激活閃爍,我也要就像禁止標準行爲一樣(按一下它變成藍色)。

我該如何在我的handleTableViewCellLongPress -Method中做到這一點?

謝謝!

+0

很好,如果你可以檢測到哪個小區長期接觸,美國可以只放一個UIImage與阿爾法或可見的uianimation。併爲藍色選擇你可以做cell.selectionStyle = UITableViewCellEditingStyleNone; – Ashishail 2012-03-09 12:39:17

回答

4

你可以使用動畫鏈接:

- (UITableViewCell *) tableView:(UITableView *)tableView 
      cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = ... 
    // remove blue selection 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

    UILongPressGestureRecognizer *gesture = [[[UILongPressGestureRecognizer alloc]  
    initWithTarget:self action:@selector(handleTableViewCellLongPress:)] autorelease]; 
    [cell addGestureRecognizer:gesture]; 

    return cell; 
} 

- (void) handleTableViewCellLongPress:(UILongPressGestureRecognizer *)gesture 
{ 
    if (gesture.state != UIGestureRecognizerStateBegan) 
    return; 

    UITableViewCell *cell = (UITableViewCell *)gesture.view; 
    [UIView animateWithDuration:0.1 animations:^{ 
    // hide 
    cell.alpha = 0.0; 
    } completion:^(BOOL finished) { 
    // show after hiding 
    [UIView animateWithDuration:0.1 animations:^{ 
     cell.alpha = 1.0; 
    } completion:^(BOOL finished) { 

    }]; 
    }]; 
}