gpt4 book ai didi

iphone - 使用 Xcode for iPhone 将 (x, y) 位置存储在某个输出文件中?

转载 作者:行者123 更新时间:2023-12-03 20:57:24 25 4
gpt4 key购买 nike

我想在 iPhone 上编写一个应用程序,我想知道这个应用程序的想法是否可行。因此,在应用程序中,我希望有一个向用户显示的图像(这很容易。当用户触摸图像时,应用程序会记录用户在图像中准确触摸的位置(x,y)并将其存储在一个文件(.pdf、.txt 或其他文件)我需要将这些 (x,y) 位置存储在某种文件中,但我不知道这在 iPone 或 iPad 中是否可行

谢谢

最佳答案

是的,这是完全可行的。你必须:

创建自定义 View 。使用如下代码覆盖 touchesBegan:withEvent: 方法:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint locationOfTouch = [touch locationInView:self];
// You can now use locationOfTouch.x and locationOfTouch.y as the user's coordinates
}

保存CGPoint。您可以像这样创建它的 NSDictionary:

NSDictionary *coordinates = (NSDictionary *) CGPointCreateDictionaryRepresentation(locationOfTouch);

然后将其写入文件:

[coordinates writeToFile:filePath atomically:YES];

仅此而已。

关于iphone - 使用 Xcode for iPhone 将 (x, y) 位置存储在某个输出文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4061144/

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