Get UITableviewCell position from “visible” area or window

梦想与她 提交于 2019-11-30 03:03:42

Yes you can use rectForRowAtIndexPath: you'll just have to pass in the indexPath of your row you've clicked.

rectForRowAtIndexPath:

Returns the drawing area for a row identified by index path.

...

EDIT

Conversion:

CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];
CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]]; 
Mickael

So here is the code i used : (it can be optimized i'm sure) :

First add NSindexPath ** property to your custom cell.
*Implement this in your tableview controller : *

-(void)addCellToFavorisWithAnimation:(ResultSearchOffreCell*)cell{
/* Generate image from cell
----------------------------------------------------------*/
UIGraphicsBeginImageContextWithOptions(cell.bounds.size, cell.opaque, [[UIScreen mainScreen] scale]);
[cell.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Launch first animation (go to top-right)
//----------------------------------------------------------*/
CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:cell.indexPath];
CGRect rectInSuperview = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];

cellAnimationContainer = [[UIImageView alloc] initWithFrame:rectInSuperview];

[cellAnimationContainer setFrame:CGRectMake(cellAnimationContainer.frame.origin.x, cellAnimationContainer.frame.origin.y+50 , cellAnimationContainer.frame.size.width, cellAnimationContainer.frame.size.height)];

[cellAnimationContainer setImage:img];

AppDelegate_Shared *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window addSubview:cellAnimationContainer];
[UIView beginAnimations:@"addFavorite-Step1" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:0.2];
[cellAnimationContainer setFrame:CGRectMake(20,cellAnimationContainer.frame.origin.y-10, cellAnimationContainer.frame.size.width, cellAnimationContainer.frame.size.height)];
[cellAnimationContainer setAlpha:0.7];
[UIView commitAnimations];
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{


/* Launch second animation => go to favoris Tab and remove from self.view
 ---------------------------------------------------------------------------*/
if([anim isEqual:@"addFavorite-Step1"])
{
    [UIView beginAnimations:@"addFavorite-Step2" context:nil]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationDelegate:self]; 
    [cellAnimationContainer setAlpha:0.4];
    [cellAnimationContainer setFrame:CGRectMake(150, 420, 20, 20)];
    [UIView commitAnimations];
}
else if([anim isEqual:@"addFavorite-Step2"])
{
    [cellAnimationContainer removeFromSuperview];
    [cellAnimationContainer release];         
}
}

Yes this is possible like that

-(void)click:(id)sender
{
    int clickcelltag;
    clickcelltag=sender.tag;

    NSIndexPath *index =[NSIndexPath indexPathForRow:clickcelltag inSection:0];

    [userreviewtblview scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES];//userreviewtblview is a UITableView name
}

Hope this will help you :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!