Dou*_*ith 5 cocoa-touch objective-c uitableview uiview ios
我知道convertRect:toRect这里的关键,但我不知道如何称呼它.我有我的单元格的子视图,我希望它在应用程序的整个窗口中的位置.
当我在其目标操作方法中点击此按钮(子视图)时,我需要知道这一点.我convertRect:toRect想,为了获得正确的坐标,我需要在单元格上调用函数,但在这种方法中,我没有引用单元格本身.
我是否爬上超级视图层次结构?这看起来很糟糕,因为我不完全确定我会得到什么,因为它嵌入在单元格的contentView中,而且Apple通过私人子视图和诸如此类的东西做了古怪的事情.
码:
@IBAction buttonPressed(sender: UIButton) {
// This button got the callback that it was pressed. It's in a cell. I need to convert its rect to that of the window here. I need the coordinate system it's calculated from (the cell) which I'm not sure of how to easily do in a target action callback.
}
Run Code Online (Sandbox Code Playgroud)
它实际上非常简单:
CGRect windowRect = [someSubview convertRect:someSubview.bounds toView:nil];
Run Code Online (Sandbox Code Playgroud)
假设你有一个按钮处理程序:
- (void)someButtonHandler:(id)sender {
UIButton *button = sender;
// do your stuff
CGRect windowRect = [button convertRect:button.bounds toView:nil];
}
Run Code Online (Sandbox Code Playgroud)
当然,如果您的方法设置为:
- (void)someButtonHandler:(UIButton *)button {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1818 次 |
| 最近记录: |