我一直在开发一个新应用程序,并且真的希望实现滑动以在我的应用程序中显示更多选项菜单。我已经搜索和搜索,但似乎没有其他人成功地使它工作(除了 Loren)。我想要做的是滑动单元格,同时使用 CABasicAnimation 将其推送到 x: 320,并在此下方添加一个子视图,该子视图将具有按钮等。我正在使用 willBeginEditing 来检测滑动以避免子类化. 这是代码:
- (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 上。
我为代码中的不良格式道歉。
在此先感谢,科林