简体   繁体   English

关于iPhone 4s,5、6和6+之间的触摸坐标

[英]About touch coordinate between iPhone 4s, 5, 6 and 6+

Fyi, I am new to Xcode programming for iOS. Fyi,我是iOS Xcode编程的新手。 I've written a simple game and tested on actual iPhone 4s and is working. 我编写了一个简单的游戏,并在实际的iPhone 4s上进行了测试,并且可以正常工作。 As I only own iPhone 4s, I can only simulate my game with iOS simulator for higher iPhone version. 由于我只有iPhone 4s,因此只能使用iOS模拟器模拟iPhone的更高版本的游戏。 The problem I observed for higher iPhone version is that the image is scaled, therefore the touch location is no longer valid. 我在较高版本的iPhone上观察到的问题是图像已缩放,因此触摸位置不再有效。

PS: I do not use any UIButton . PS:我不使用任何UIButton I am using CGRectMake to create the button and later declare the touch position as shown below. 我正在使用CGRectMake创建按钮,并稍后声明触摸位置,如下所示。

-(void) touchBegan: (CGPoint) p 
{
    if (p.x > 0 && p.x < 100 && p.y > 0 && p.y < 30) myscore = 1;
}

So my question is, will the touch displacement seen in the simulator appear the same in the actual device? 所以我的问题是,模拟器中看到的触摸位移在实际设备中会不会看起来一样? If yes, does it mean that I need to declare the touch boundary for each iPhone version? 如果是,这是否意味着我需要为每个iPhone版本声明触摸边界?

If you want to fix the touch location regardless of the device you're using, the easier way is to, as said before, click and drag a Button on the storyboard and use Auto-Layout to fix the location of the button For instance, you can set the button to appear 10px down and 10px right from the top-left corner from the containing view and it will appear at the same location regardless of the device used. 如果您想固定触摸位置而不管所使用的设备是什么,那么更简单的方法是,如前所述,在情节提要板上单击并拖动一个按钮,然后使用“自动布局”来固定该按钮的位置。例如,您可以将按钮设置为从包含视图的左上角向下显示10px,右上角显示10px,无论使用哪种设备,该按钮都将出现在相同的位置。 But I'm sure there's a way to programmatically do the exact same thing 但是我敢肯定,有一种方法可以通过编程来完全相同地做

PS: wanted to post a comment and not an answer, but I don't have enough rep... PS:想发表评论而不是回答,但我没有足够的代表...

Yes, this will happens in device to. 是的,这将发生在设备中。 As you comment you can set the bounds for each different device or (i think easier) use a UIButton. 当您发表评论时,您可以为每个不同的设备设置界限,或者(我认为比较容易)使用UIButton。 Why don't you use it ? 你为什么不使用它? Any special reason? 有什么特殊原因吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM