我有一个与TableView中其上具有UILabels和UIButtons定制TableCellViews。 当按下其中一个按钮录音我要显示一个“工具提示”描述该按钮的文本。

最一切,除了工作时,我尝试转换UIButton的中心坐标是一个UIView的rootView的坐标。

下面是代码:

- (void) fancyLabelButtonPressed: (UIButton *) button {
  CGPoint btnPoint = button.center;   // x=200.5 y=27.5
  CGPoint rootViewPoint = [button convertPoint:btnPoint toView:rootView];
  // rootViewPoint -> x=390.5 y=197.5
  CGPoint pointToUse = CGPointMake(btnPoint.x +20, rootViewPoint.y - 23); // Hack to get it close
}

当我在纵向视图是如何rootViewPoint.x=390.5?!?通过使用从按钮x和从rootViewPoint我去接近它应该是什么,但它只是一个黑客在y。

有谁看到我在做什么错?或者是有更好的方法?

有帮助吗?

解决方案

这是因为你从错误的视图转换的点。该center属性实际上是按钮的上海华,不管它是什么的坐标系中,所以当你将它转换为你rootView,则必须将其从那里转换。所以:

rootViewPoint = [[button superview] convertPoint:btnPoint toView:rootView];

这应该给你你在找什么。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top