美文网首页
获取cell在self.view/subview/window中

获取cell在self.view/subview/window中

作者: sunflower1518 | 来源:发表于2016-01-05 10:15 被阅读409次

1.cell 在subview中的位置


34D1A0B7-0968-448D-89A8-E60C3D63AC42.jpg
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger sectionIndex = indexPath.section;
    NSInteger cellIndex = indexPath.row;
    
    //cell在tableview中坐标
    CGRect cellRectInTableview = [tableView rectForRowAtIndexPath:indexPath];
    

    UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    
    //cell在window中的位置
    CGRect cellRectInWindow = [cell convertRect:cell.bounds toView:nil];
    //cell在selfview中的位置
    CGRect cellRectInSelfView = [cell convertRect:cell.bounds toView:self.view];
}

获取btn所在的cell indexPath

- (void) init
{
    [cell.btn addTarget:self
                 action:@selector(btnClick:event:)
       forControlEvents:UIControlEventTouchUpInside];
}

- (void)btnClick:(id)sender event:(id)event {
    
    NSSet *touches =[event allTouches];
    
    UITouch *touch =[touches anyObject];
    
    CGPoint position = [touch locationInView:self.tableView];
    
    NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:position];
    if (indexPath!= nil) {
        
        // ....
        
    }
}

        //bgview Y移动200dp
        self.bgView.transform = CGAffineTransformMakeTranslation(0, -200);

        //topTransformView顺时针旋转1.5π
        self.topTransformView.transform = CGAffineTransformMakeRotation(M_PI*1.5);

相关文章

网友评论

      本文标题:获取cell在self.view/subview/window中

      本文链接:https://www.haomeiwen.com/subject/jbczhttx.html