我想将UITableViewCell的颜色从一种颜色缓慢更改为另一种颜色,同时我将单元格保持(点击保持)特定持续时间。
在那段时间之后,它应该执行一个动作。它就像 Android 上的 Whatsapps 行选择一样。它首先是亮的,最后是最暗的颜色。
我已经用手势识别器试过了,但是没有用..
那可能吗?我会很感激一个示例代码。
编辑1:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CostumEventCell *cell = [eventsTable cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor colorWithRed:(252/255.0) green:(213/255.0) blue:(183/255.0) alpha:1]];
[UIView animateWithDuration:3.0 animations:^(void) {
[cell setBackgroundColor:[UIColor colorWithRed:(204/255.0) green:(85/255.0) blue:(0/255.0) alpha:1]];
}];
}
** EDIT 2(带有手势识别器):**
- (void) createGestureListener{
UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPress:)];
longPressRecognizer.delegate = self;
[self.eventsTable addGestureRecognizer:longPressRecognizer];
}
-(void)onLongPress:(UILongPressGestureRecognizer*)pGesture
{
CGPoint touchPoint = [pGesture locationInView:self.view];
NSIndexPath* row = [eventsTable indexPathForRowAtPoint:touchPoint];
if (pGesture.state == UIGestureRecognizerStateBegan)
{
//Do something to tell the user!
NSLog(@"Tap started");
CostumEventCell *cell = [eventsTable cellForRowAtIndexPath:row];
[UIView animateWithDuration:3.0 animations:^(void) {
[cell setBackgroundColor:[UIColor colorWithRed:(252/255.0) green:(213/255.0) blue:(183/255.0) alpha:1]];
[cell setBackgroundColor:[UIColor colorWithRed:(204/255.0) green:(85/255.0) blue:(0/255.0) alpha:1]];
}];
}
}