美文网首页
iOS 获取cell及其控件在屏幕中的位置

iOS 获取cell及其控件在屏幕中的位置

作者: gaookey | 来源:发表于2020-09-22 15:28 被阅读0次

cell 在屏幕中的位置

let rect = tableView.convert(tableView.rectForRow(at: indexPath), to: tableView.superview)

cell 中的控件在屏幕中的位置

class MyTableViewCell: UITableViewCell {
    
    //省略代码
    ......
    
    @objc func imageClick(tap: UITapGestureRecognizer) {
        guard let image = tap.view else { return }
        //let window = UIApplication.shared.windows.filter{ $0.isKeyWindow }.first
        let rect = image.convert(image.convert(image.frame, from: contentView), to: window)
    }
    
    @objc func buttonClick(_ button: UIButton) {
        //let window = UIApplication.shared.windows.filter{ $0.isKeyWindow }.first
        let rect = button.convert(button.convert(button.frame, from: contentView), to: window)
    }
}

相关文章

网友评论

      本文标题:iOS 获取cell及其控件在屏幕中的位置

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