我正试图动画UITableView
并遇到困难。我使用自定义单元格加载了表格,我需要再次获取该表格的元素,并在动画中向下移动该行的内容。
当我执行此操作时,我只能从UIView中获取整个表格。实际上我想从表中获取自定义表格单元格内容并在其上执行动画。
我正在努力:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel *temp=[[UILabel alloc]init];
temp.text=nil;
UIView *anim = nil;
id currentObject;
for (UIView *theview in destination.superview.subviews)
{
if ([theview isKindOfClass:[UITableView class]])
{
NSLog(@"%@",theview);
UIView *vi= theview;//(UITableView *)[UITableView class];
NSLog(@"%@",vi);
for(UIView *vi1 in vi.superview.subviews )
{
if ([vi1 isKindOfClass:[UITableViewCell class]])
{
NSLog(@"%@",vi1);
}
anim = theview;
break;
}
}
}
如何从中获取数据?
答案 0 :(得分:0)
现在我刚刚创建了自定义UILable并将我的单元格文本分配给它然后动画了.... 这是代码......
在表viewDidSelect方法中我编码了这个....
NSArray *visibleCells = [tableView visibleCells];
NSLog(@"the count %d",[visibleCells count]);
//UITableViewCell *aCell=[tableView cellForRowAtIndexPath:indexPath];
UITableViewCell *visiblecell=[tableView cellForRowAtIndexPath:indexPath];
NSLog(@"the count %@",aCell);
NSLog(@"The visible cell ::%@",visiblecell);
int i=0;
for (UITableViewCell *theCell in visibleCells)
{
if ([theCell isEqual:visiblecell])
{
selectedView.frame =CGRectMake( 0,i*(480/[visibleCells count]),320,50);
break;
}
i++;
}
anim=selectedView;
if (!anim)
return;
[self pathGenerate:anim];
我有一个单独的动画功能,只是我称之为......
- (void)pathGenerate:(UIView *)anim
{
// [self.tabBarController.tabBar insertSubview:(UIImageView*)[UIImage imageNamed:@"Coffee_smoke.png"] atIndex:0];
self.tabBarItem.image=nil;
UIBezierPath *movePath = [UIBezierPath bezierPath];
[movePath moveToPoint:anim.center];//-->down---->destinationPoint.center
[movePath addQuadCurveToPoint:CGPointMake(170, 420)
controlPoint:CGPointMake(200,10)];/* // 2nd phase //destinationPoint.center.x+200, destinationPoint.center.y-100)];*/
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnim.path = movePath.CGPath;
moveAnim.removedOnCompletion = YES;
CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
scaleAnim.removedOnCompletion = YES;
CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
opacityAnim.removedOnCompletion = YES;
CAAnimationGroup *animGroup = [CAAnimationGroup animation];
animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
animGroup.duration = 0.5;
[anim.layer addAnimation:animGroup forKey:nil];
// self.tabBarItem.image=[UIImage imageNamed:@"Coffee_smoke.png"];
}