我一直在研究一個新的應用程序,並且真的希望實施一個刷卡以在我的應用程序中顯示更多選項菜單。我已經搜索和搜索,但似乎沒有人成功地使它工作(除了羅蘭)。我想要做的是刷單元格,並同時使用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