滑动以显示像Tweetie的菜单
我一直在研究一个新的应用程序,并且真的希望实施一个刷卡以在我的应用程序中显示更多选项菜单。我已经搜索和搜索,但似乎没有人成功地使它工作(除了罗兰)。我想要做的是刷单元格,并同时使用CABasicAnimation将其推到x:320,并添加一个子视图下面,将有按钮等。我使用willBeginEditing检测滑动,以避免子类化。下面的代码:滑动以显示像Tweetie的菜单
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.0;
theAnimation.repeatCount=0;
theAnimation.autoreverses=NO;
theAnimation.removedOnCompletion = NO;
theAnimation.fillMode = kCAFillModeForwards;
theAnimation.fromValue=[NSNumber numberWithFloat:0];
theAnimation.toValue=[NSNumber numberWithFloat:+320];
[cell.layer addAnimation:theAnimation forKey:@"animateLayer"];
CGRect frame = CGRectMake(0, 59 * indexPath.row, 320, 59);
UIView *menu = [[[UIView alloc] initWithFrame:frame] autorelease];
NSString *path = [NSString stringWithFormat:@"%@%@",
[[NSBundle mainBundle] resourcePath],
@"/flick.wav"];
SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
AudioServicesPlaySystemSound(soundID);
self.menu.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"dots.png"]];
[self.view addSubview:menu];
[self.view sendSubviewToBack:menu];
}
- (void)animationDidStop:(NSString*)animationID finished:(BOOL)finished context:(void *)context
{
// Release
[self release];
}
#pragma mark - Swipe Menu II
- (void)scrollViewDidScroll:(UIScrollView *)tableView {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:nil];
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
theAnimation.duration=0.2;
theAnimation.repeatCount=0;
theAnimation.autoreverses=NO;
theAnimation.fromValue=[NSNumber numberWithFloat:320];
theAnimation.toValue=[NSNumber numberWithFloat:0]
;
[cell.layer addAnimation:theAnimation forKey:@"animateLayer"];
}
的问题是向后滑动电池 - 我要收到菜单视图以外的任何触摸什么时候做,而是因为它是滚动型的,我不能。 ScrollViewdidScroll方法只会在单元格滚动视口后将单元格恢复到正常位置。 (如在NavigationBar或遮挡它的对象下)最后一个关键问题是能够检测菜单是否已经可见或活动,并且单元格已经离开屏幕,将单元格滑回原始位置,删除菜单视图,然后滑出另一个单元格并添加菜单。
我想成为第一个在Loren身上实现这一点的人,因为很多人都尝试过,特别是在*上。
我为代码中糟糕的格式道歉。
由于提前, 歌林
我实际上做这项工作相当不错,你可以看看这里的项目:http://www.thermoglobalnuclearwar.com/opensource/
它还克服了特威特在那里你可以不先刷别的两次刷卡同一小区的问题。
如果您做出任何有建设性的更改或需要任何帮助,请告诉我!
感谢您的代码!我会看看它,看看我能用它做什么! – 2010-07-07 22:42:07
不是问题:) – 2010-07-07 22:54:11
你介意帮我实施它到我的应用程序?我有的配置是不同的,我似乎无法得到它的工作。 – 2010-07-08 04:40:16
罗兰的实现有一个致命的缺陷,这就是,如果你刷卡的单元格,然后滚动表,直到你刷卡不同的细胞则无法重新刷相同的细胞。我相信这是因为tableview认为单元格仍在编辑,直到您尝试“编辑”另一个单元格为止。
您可能想要调查其他方法,例如使用附加到单元格的UISwipeGestureRecognizer来检测滑动。
我可以想出两种方法来尝试和检测单元格外的水龙头。第一个是对UIApplication进行子类化并覆盖-sendEvent:
。您可以使用它来检测轻敲事件并关闭单元格“编辑”。这里的主要问题是给UIApplication子类关于你的单元格的知识。第二种方法是在整个屏幕上拍摄自定义的UIView子类,并在-hitTest:withEvent:
中测试触摸是否属于您的手机区域。如果没有,请关闭单元格“编辑”。在这两种情况下,都返回nil以允许事件进行到底层视图(并且不要忘记在事件发生后删除此覆盖视图)。您可能还想要测试UIEvent,以确保它在解除单元格之前包含新的触摸。
感谢您的回答并解释它!我将研究汤姆的代码,因为它似乎修复了Tweetie/Twitter的问题。 – 2010-07-07 22:35:29
当你点击一个帖子上的+按钮时,你的描述听起来像是发生在脸书上的事情,该按钮显示下面的/评论按钮。如果你还没有看过http://github.com/facebook/three20,你可以看看。 – 2010-07-08 04:48:01