- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
UIView 具有以下内容:
- convertPoint:toView:
- convertPoint:fromView:
- convertRect:toView:
- convertRect:fromView:
Android 的等价物是什么?更一般地说,给定两个 View
,如何在第一个 View
的坐标系中获取第二个 View
的矩形?
最佳答案
我认为 sdk 中没有等效项,但您似乎可以使用 getLocationOnScreen
轻松编写自己的实现:
public static Point convertPoint(Point fromPoint, View fromView, View toView){
int[] fromCoord = new int[2];
int[] toCoord = new int[2];
fromView.getLocationOnScreen(fromCoord);
toView.getLocationOnScreen(toCoord);
Point toPoint = new Point(fromCoord[0] - toCoord[0] + fromPoint.x,
fromCoord[1] - toCoord[1] + fromPoint.y);
return toPoint;
}
public static Rect convertRect(Rect fromRect, View fromView, View toView){
int[] fromCoord = new int[2];
int[] toCoord = new int[2];
fromView.getLocationOnScreen(fromCoord);
toView.getLocationOnScreen(toCoord);
int xShift = fromCoord[0] - toCoord[0];
int yShift = fromCoord[1] - toCoord[1];
Rect toRect = new Rect(fromRect.left + xShift, fromRect.top + yShift,
fromRect.right + xShift, fromRect.bottom + yShift);
return toRect;
}
关于android - UIView 的 convertRect/convertPoint 函数的 android 等价物是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31578204/
我正在尝试了解这些方法的功能。你能给我提供一个简单的用例来理解它们的语义吗? 以文档为例,convertPoint:fromView:方法描述如下: Converts a point from the
我有一个名为RulerView的 View ,它有一个 subview : StickerImageView 这个ImageView包含图像,我可以在上面添加可移动的TextView。 现在我想要的是
我正在按照斯坦福大学类(class)学习 Swift 语言。第五讲有一个画笑脸的demo。 有faceCenter的声明,代码如下。 var faceCenter: CGPoint { ret
我试图弄清楚如何在 swift 游乐场中使用 UIView 的 convertPoint 函数。我没有得到我期望的结果,我不知道为什么。 当我尝试时: import UIKit let large =
我读过这个iPhone - Get Position of UIView within entire UIWindow和其他人多次,但就是无法让我的应用程序向我输出某物在屏幕上的绝对位置。 我有一个
我正在尝试同时学习 Swift 和 Cocoa。我有一个 NSView 的子类(实际上是 NSControl 的)。在这个子类中,我尝试运行以下行: self.convertPoint(aPoint:
我在另一个 JPanels 结构复杂、代码多的项目中遇到了这个问题。 在那里我有以下片段 Point point = label.getLocation(); Point point2 = Swing
我不太明白方法convertPoint:toView:。 在 Apple 的文档中写道 convertPoint:toView: Converts a point from the receiver’
所以我有一个自定义的 tableview,在那个 tableview 中我有一个按钮、一个图像和 2 个标签。这些项目中的每一个都使用 php 填充来自 mysql 服务器的 json 数据。我将我的
我对 SKNode 的方式有点困惑方法 convertPoint:fromNode:和 convertPoint:ToNode:正在工作,我已经查看了文档,但它们的作用并不那么明显。例如,这个(见下图
我已经查看了有关此主题的十几个 SO 问题,但没有一个答案对我有用。也许这会帮助我回到正确的道路上。 想象一下这个设置: 我想获取 UIButton 相对于 UIView 的 center 坐标。 也
我很高兴看到这个:answer for how to convert point of a subview它在模拟器上非常适合我。 但由于某种原因,它在设备上不起作用...会不会是设备对 View 位
我正在编写一个方法,它应该接收一个点:'in_centre',它将在当前 View 的坐标系中(也作为另一个参数传递:'target') 我需要将这个点转换成窗口坐标。 文档说我应该通过将这里的第二个
UIView 具有以下内容: - convertPoint:toView: - convertPoint:fromView: - convertRect:toView: - convertRect:f
请看下面的图片: 在这里,我想要将我的 UITextField C 透视图的 CGPoint 获取到主 UIViewController Z。我正在从主 UIViewController Z 转换它的
在这里,我从 Parse 检索了数据,并在 tableViewCell 中显示该数据。 override func tableView(tableView: UITableView, cellForR
我是一名优秀的程序员,十分优秀!