Kol*_*kel 1 iphone core-animation uitableview cabasicanimation
我一直在研究一个新的应用程序,并且真的希望实现一次滑动以在我的应用程序中显示更多选项菜单.我进行了搜索和搜索,但似乎没有其他人成功地使其工作(除了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"];
}
Run Code Online (Sandbox Code Playgroud)
问题是单元格的向后滑动 - 我想在收到菜单视图外的任何触摸时这样做,但因为它是一个scrollView,我不能.ScrollViewdidScroll方法仅在滚动视口后将单元格动画回其正常位置.(如在NavigationBar或隐藏它的对象下)最后一个关键问题是能够检测菜单是否已经可见或活动且单元格已经离开屏幕,将单元格滑回原始位置,删除菜单视图,然后滑出另一个单元格并添加菜单.
我希望成为第一个与Loren一起实现这一点的人,就像许多其他人一样,特别是在StackOverflow上.
我为代码中的糟糕格式道歉.
谢谢你,Kolin
我实际上做得很好,你可以在这里查看项目:http://www.thermoglobalnuclearwar.com/opensource/
它还克服了Tweetie中的问题,在没有先擦别去的情况下你不能刷两次相同的细胞.
如果您做出任何建设性的更改或需要任何帮助,请告诉我们!
| 归档时间: |
|
| 查看次数: |
5777 次 |
| 最近记录: |