当前位置: 代码迷 >> Iphone >> 获取cell中的button在整个荧幕上的位置
  详细解决方案

获取cell中的button在整个荧幕上的位置

热度:157   发布时间:2016-04-25 05:32:25.0
获取cell中的button在整个屏幕上的位置

编写cell中得button点击事件

- (IBAction)showButtonClick:(id)sender

{

    UIButton *button = (UIButton *)sender;

    

    UIWindow* window = [UIApplication sharedApplication].keyWindow;

    CGRect rect1 = [button convertRect:button.frame fromView:self.contentView];     //获取button在contentView的位置

    CGRect rect2 = [button convertRect:rect1 toView:window];         //获取button在window的位置

    CGRect rect3 = CGRectInset(rect2, -0.5 * 8, -0.5 * 8);          //扩大热区

 

    //rect3就是最终结果。

}

  相关解决方案