- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
- locationInView: Returns the current location of the receiver in the coordinate system of the given view.
This method returns the current location of a UITouch object in the coordinate system of the specified view. Because the touch object might have been forwarded to a view from another view, this method performs any necessary conversion of the touch location to the coordinate system of the specified view.
- (void)sendEvent:(UIEvent *)event
{
if([event type] == UIEventTypeTouches)
{
NSSet<UITouch *> *allTouches = [event allTouches];
if(allTouches)
{
for(UITouch* touch in allTouches)
{
if([touch type] == UITouchTypeDirect)
{
// This is 640x1136
CGRect bounds = [myWindow bounds];
// This is in [318x560] empirically
CGPoint origin = [touch locationInView:myWindow];
}
}
}
}
}
谁能解释一下?
来自问题:
myWindow = [[myWindow alloc] initWithFrame:[[UIScreen mainScreen] nativeBounds]];
在 application: application didFinishLaunchingWithOptions: launchOptions
CAEAGLLayer
层最佳答案
每个 View 都有一个 contentScaleFactor 属性。它旨在简化不同设备分辨率的工作(例如视网膜(@2x)、非视网膜(@1x)、@3x 等)UIWindow
是 UIView
的子类,所以它也有它。
The scale factor determines how content in the view is mapped from the logical coordinate space (measured in points) to the device coordinate space (measured in pixels). This value is typically either 1.0 or 2.0. Higher scale factors indicate that each point in the view is represented by more than one pixel in the underlying layer. For example, if the scale factor is 2.0 and the view frame size is 50 x 50 points, the size of the bitmap used to present that content is 100 x 100 pixels.
The default value for this property is the scale factor associated with the screen currently displaying the view. If your custom view implements a custom drawRect: method and is associated with a window, or if you use the GLKView class to draw OpenGL ES content, your view draws at the full resolution of the screen. For system views, the value of this property may be 1.0 even on high resolution screens.
因此在您的情况下,[myWindow bounds]
返回等于设备屏幕大小的逻辑大小,因为您将其设置为 native 边界。在根据其比例因子(等于 2)从其逻辑坐标计算出的设备坐标中,您的窗口比屏幕大两倍,而您的触摸仅触及屏幕的四分之一。
myWindow = [[myWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
myWindow.layer.contentsScale = [[UIScreen mainScreen] nativeScale];
CGPoint origin = [touch locationInView:myWindow];
origin.x *= [[UIScreen mainScreen] scale];
origin.y *= [[UIScreen mainScreen] scale];
关于iOS触摸坐标系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35591681/
我一直在试图弄清楚小部件的坐标是如何到达的。例如在 qt 文档中,我想知道这是如何完成的。 QGridLayout *layout = new QGridLayout; layout->ad
我正在尝试在 libGDX 中正确配置我的 Camera 和 Sprite,以正确显示在 2D 坐标系中,原点位于左下角。 我像这样设置我的相机: cameraWidth = Gdx.graphics
我最近查看了 App Store 中提供的 Swift Playgrounds 应用程序,在那里我偶然发现了这个交互式坐标系 View ,类似于可以在 Mac 上的 Xcode playgrounds
我知道 Posit 会计算相机和 3d 对象之间的平移和旋转。我现在唯一的问题是,我不知道相机和物体的坐标系是如何定义的。因此,例如,如果我绕 z 轴旋转 90°,z 轴指向哪个方向,物体是绕这个轴旋
我想完成以下事情。我有一组PDF文件,首先我想检查坐标系的原点。如果 pdf 坐标系的原点不是左上角 [通常原点在左下角],我想创建一个坐标在左上角的结果 PDF。我正在尝试使用 PDFBox [下面
我有来自 AVAsset 的 CVPixelBufferRef。我正在尝试对其应用 CIFilter。我使用这些行: CVPixelBufferRef pixelBuffer = ... CVPixe
我很难理解 OpenLayers 使用的坐标系。 英国莱斯特大约在。 Latitude: 52.63973017532399 Longitude: -1.142578125 但要使用 OpenLay
我刚开始iOS绘图编程,发现坐标系和Mac OS X不同,基本上iOS上的原点在左上角,而不是像Mac上的左下角。只是想知道是否有人知道 Apple 为何做出此更改,以及 Mac 的 future 也
我想更改 PDF 坐标系以更改原点 (0,0) -> 从左下角到左上角。因此,例如,当我在 x=5 y=10 的位置书写文本时,它将以从左数起 10 点和从上数(而不是从下数)开始的 10 点书写。
我有以下代码: QGraphicsScene* pScene = new QGraphicsScene(this); ui->graphicsView->setScene(pScene); pScen
我目前正在尝试实现一个基于室内地图的 AR 浏览器,但我面临几个问题,让我们看一下图: 在这个图中,我已经将坐标更改为OpenGL的右手坐标系。 在我们的真实场景中, 给定角度 FOV/2 和相机高度
我正在尝试在 ios 中构建自定义 warp 内核。 我有这个内核代码 var kernelCode = " kernel vec2 partialFlip(vec2 center,
我在我的旧手机 (Samsung Galaxy Ace) 上测试我的“游戏”,我把它给了我妈妈,所以我现在使用的是平板电脑 (Samsung GT-P7300),但我在当我触摸屏幕时的坐标。我在 An
我正在开发一个网络应用程序,它包括一个我绘制函数图形的部分,坐标系是由 Canvas 制作的。问题是,我无法放大坐标系。我想让它能够放大和缩小+使用鼠标移动坐标系。放大/缩小时,x 和 y 值也应该增
我的问题类似于Changing sensor coordinate system in android 无论设备方向如何,我都希望能够相互比较用户的 Action 。因此,当用户以纵向握住手机并弯曲
我正在尝试使用 stereoRectify。我没有使用 stereoCalibrate 校准我的相机,而是已经有了一些信息,我将使用这些信息来创建相机矩阵,这些矩阵是 stereoRectify 的输
我在矩阵中有一个对象的足迹,简而言之,对象占用了哪些单元格(对象是一个部分,标记为 0 的单元格未被占用,标记为 1 的单元格被对象占用)。然后,我在 list > 中有一个已占用单元格的列表。与矩阵
我是 Canvas 的新手,想知道: 使用倒笛卡尔坐标系的基本原理。 比如说,我需要在直方图中绘制一些值。是一种将 Canvas 框架旋转/映射到笛卡尔坐标系的简单方法。? 最佳答案 Canvas 是
通读 SVG 1.1 specification ,我试图了解用于定义初始视口(viewport)的单位与文档其余部分使用的单位之间的关系。 如果视口(viewport)最初是使用点定义的 并且文档
好的,所以我找到了这个 thread ,这是我认为我需要做的。但是,我使用的不是 GL10,而是 GLES20。 glOrthof 不是 GLES20 API 的一部分。 我想做的是改变坐标系的范围,
我是一名优秀的程序员,十分优秀!