獲取cell在self.view/subview/window中的位置

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);
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容