ios 如何在屏幕上显示所有触摸以演示 iPhone 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6686659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:44:45  来源:igfitidea点击:

How do I display all touches on screen in order to demo an iPhone app?

iphoneiosuitouch

提问by Alex Argo

Now that we have display mirroring on the iPad 2 (wired now... wireless coming in iOS 5), is there an easy way to display all touches on screen? This would be useful when demoing an app?

现在我们在 iPad 2 上有显示镜像(现在有线……iOS 5 中的无线功能),有没有一种简单的方法可以在屏幕上显示所有触摸?这在演示应用程序时会有用吗?

What I am looking for is the ability to just include some SDK, and maybe change a line of code after which all of my touches will be displayed on screen.

我正在寻找的是能够只包含一些 SDK,并且可能会更改一行代码,之后我的所有触摸都会显示在屏幕上。

I have seen many other ways to demo apps: 1)Using the simulator along with a screen capture tool that will turn your mouse cursor into a big white circle 2)Jailbreak hacks that can record the screen/display all touches

我见过许多其他演示应用程序的方法:1) 使用模拟器和屏幕捕获工具,将鼠标光标变成一个大的白色圆圈 2) 可以记录屏幕/显示所有触摸的越狱黑客

However, my goal is to just have touches displayed on a regular app running on an actual device.

但是,我的目标是只在实际设备上运行的常规应用程序上显示触摸。

回答by hypercrypt

You can use Touchposé: https://github.com/toddreed/Touchpose

您可以使用 Touchpose:https: //github.com/toddreed/Touchpose

回答by Kane Cheshire

I realise this question is old now, but none of the existing solutions were good enough for me. I needed something that worked out of the box with multiple windows, without having to subclass windows or do any fiddling about.

我意识到这个问题现在已经过时了,但是现有的解决方案都对我来说不够好。我需要一些可以在多个窗口中开箱即用的东西,而不必对窗口进行子类化或做任何摆弄。

So I created ShowTime, which (up until Swift 4) literally just requires you to either add the pod to your podfile or add ShowTime.swift to your target. The rest is totally automatic unless you want to configure the defaults.

所以我创建了 ShowTime,它(直到 Swift 4)实际上只需要您将 pod 添加到您的 podfile 或将 ShowTime.swift 添加到您的目标。除非您想配置默认值,否则其余部分是完全自动的。

https://github.com/KaneCheshire/ShowTime

https://github.com/KaneCheshire/ShowTime

Starting from Swift 4 there's one extra step, in your AppDelegate, just set ShowTime.enabled = .alwaysor ShowTime.enabled = .debugOnly

从 Swift 4 开始,还有一个额外的步骤,在您的 AppDelegate 中,只需设置ShowTime.enabled = .alwaysShowTime.enabled = .debugOnly

Edit: Swift 4 now has auto-enabling again so no need to manually enable.

编辑:Swift 4 现在再次自动启用,因此无需手动启用。

回答by Steven W. Disbrow

After looking at all of the various libraries for this, I realized that, at least in my case, they were massive overkill. I just wanted to make an App Preview video, and I just needed it for two places in my app.

在查看了所有不同的库之后,我意识到,至少在我的情况下,它们是巨大的矫枉过正。我只是想制作一个应用预览视频,我只需要在我的应用中的两个地方使用它。

So, I spent a little time and came up with the following code that you can use with a SpriteKit-based scene to enable touch display on a scene-by-scene basis. (And, if you are starting from scratch, you could subclass SKScene and bake this right in for use by all your scenes.)

因此,我花了一点时间想出了以下代码,您可以将其与基于 SpriteKit 的场景一起使用,以逐个场景地启用触摸显示。(而且,如果您是从头开始,您可以将 SKScene 子类化并烘焙它以供所有场景使用。)

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInNode:self];
    SKNode *node = [self nodeAtPoint:location];

#ifdef weBeRecording
    // ^^ Only do this if we're building a special version for making App Previews
    // Could also be switched on and off by a runtime control, I suppose

    // Create a new SKSprite at the touch location
    SKSpriteNode *touchesNode = [SKSpriteNode spriteNodeWithImageNamed:@"touchMarker.png"];
    touchesNode.position = location;

    // Initially see-through
    touchesNode.alpha = 0.0;

    // Position it above all your other nodes
    touchesNode.zPosition = 199;

    // And size it appropriately for your needs
    touchesNode.size = CGSizeMake(80, 80);

    // Add it to the scene
    [self addChild:touchesNode];

    // And then make it fade in and out. (Adjust in and out times as needed.)
    SKAction *showTouch =
    [SKAction sequence:@[
                         [SKAction fadeInWithDuration:0.25],
                         [SKAction fadeOutWithDuration:0.25],
                         [SKAction removeFromParent]
                         ]];
    [touchesNode runAction:showTouch];
#endif

    /* process original touch on node here */
}

Of course, you'll have to make the touchMarker.png file yourself. I created mine in Photoshop and it's just a simple 100x100 white circle with a 50% transparency. Honestly, it took longer to get that image just right than it did to get the code working. (If there's a way to attach images here, I'll do that. But, um, it's my first day. Yeah.)

当然,您必须自己制作 touchMarker.png 文件。我在 Photoshop 中创建了我的,它只是一个简单的 100x100 白色圆圈,透明度为 50%。老实说,使图像恰到好处比使代码正常工作花费的时间更长。(如果有办法在此处附加图像,我会这样做。但是,嗯,这是我的第一天。是的。)

One caveat, you have find and save off the originally touched node (saved here in the "node" variable) before you do this. If you don't, that original value gets lost and none of your node testing will work after you display the touch marker.

一个警告,在执行此操作之前,您已经找到并保存了最初接触的节点(此处保存在“节点”变量中)。如果不这样做,则原始值将丢失,并且在您显示触摸标记后,您的任何节点测试都将无效。

Hope this helps someone else!

希望这对其他人有帮助!

Diz

迪兹

回答by Benjamin Mayo

You'd have to code in custom touches on the container view and move the center of a circular view to the touch's locationInView.

您必须在容器视图上的自定义触摸中进行编码,并将圆形视图的中心移动到触摸的 locationInView。

回答by huesforalice

I would probably try to capture all touches on the KeyWindow with touchesBegan, touchesMoved and touchesEnded. You could then have a transparent view lying over the application which would then show the touches at the appropriate location.

我可能会尝试使用 touchesBegan、touchesMoved 和 touchesEnded 来捕获 KeyWindow 上的所有触摸。然后,您可以在应用程序上放置一个透明视图,然后在适当的位置显示触摸。