我一直在研究一个新的应用程序,并且真的希望实施一个刷卡以在我的应用程序中显示更多选项菜单。我已经搜索和搜索,但似乎没有人成功地使它工作(除了罗兰)。我想要做的是刷单元格,并同时使用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身上实现这一点的人,因为很多人都尝试过,特别是在StackOverflow上。
我为代码中糟糕的格式道歉。
由于提前, 歌林
当你点击一个帖子上的+按钮时,你的描述听起来像是发生在脸书上的事情,该按钮显示下面的/评论按钮。如果你还没有看过http://github.com/facebook/three20,你可以看看。 – 2010-07-08 04:48:01