gpt4 book ai didi

iphone - 使用触摸事件的 locationInView 时,如何确定设备上 CGPoint 的有效范围?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:48:39 25 4
gpt4 key购买 nike

我知道 iPhone 的分辨率为 480 x 320,iPad 的分辨率为 1024 x 768,但我不知道如何以编程方式确定。如果能得到任何帮助,我将不胜感激。

最佳答案

UITouch*yourTouchNameHere = [touches anyObject];
CGPoint yourPointNameHere=[touch locationInView:self.view];

这自动意味着触摸在屏幕上,因此返回的任何触摸点都是有效的,但下面的代码仍然可以帮助您理解:


接收屏幕尺寸:[UIScreen mainScreen].bounds.size

返回的 iOSDevice 高度(以像素为单位):

[UIScreen mainScreen].bounds.size.height

返回的 iOSDevice 宽度(以像素为单位):

[UIScreen mainScreen].bounds.size.width

iOSDevice 是 iPhone 吗:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){}

iOSDevice 是 iPad 吗:

if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){}

另一个 stackOverflow question here表明您还可以使用

以点为单位返回整个屏幕分辨率(320x400 等):

CGRect screenBounds = [[UIScreen mainScreen] bounds];

返回屏幕分辨率比例:

CGFloat screenScale = [[UIScreen mainScreen] scale];

另一种获取像素宽度和高度的方法包括上面两行:

CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);

关于iphone - 使用触摸事件的 locationInView 时,如何确定设备上 CGPoint 的有效范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12556541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com