私は新しいアプリに取り組んでおり、アプリケーション内でより多くのオプション メニューを表示するためにスワイプを実装することを本当に望んでいました。私は検索して検索しましたが、他の誰もうまく機能させていないようです (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"];
}
問題は、セルのスライド バックです。メニュー ビュー以外のタッチを受信したときに実行したいのですが、scrollView であるため、できません。ScrollViewdidScroll メソッドは、セルがビューポートからスクロールされると、セルをアニメーション化して通常の場所に戻すだけです。(NavigationBar またはそれを隠すオブジェクトの下のように) 最後の重要な問題は、メニューが既に表示されているかアクティブであり、セルが既に画面から外れているかどうかを検出し、セルを元の位置にスライドして戻し、削除する機能です。メニュー ビューを開き、他のセルをスライドしてメニューを追加します。
多くの人が特に StackOverflow で試みたように、私は Loren のほかにこれを実装する最初の人になりたいと思っています。
コードの書式設定が不十分であることをお詫びします。
前もってありがとう、コーリン