xcode 使用 iOS 设备调试时切换慢速动画
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10229375/
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
Toggle slow animation while debugging with iOS Device
提问by fabregas88
I'm using xCode 4.3.1 and I need to use the option that the iOS Simulator has => Debug -> Toggle Slow Animation but while debugging with the iOS Device.
我正在使用 xCode 4.3.1,我需要使用 iOS 模拟器具有的选项 => 调试 -> 切换慢速动画但同时使用 iOS 设备进行调试。
Is it possible?
是否可以?
回答by Tim Camber
It's not possible in exactly the same way as with the Simulator, but there is a good way to accomplish the same effect using lldb.
不可能以与模拟器完全相同的方式实现,但有一种使用 lldb 实现相同效果的好方法。
Use the debugger to pause code execution, and then enter the command:
使用调试器暂停代码执行,然后输入命令:
p [(CALayer *)[[[[UIApplication sharedApplication] windows] objectAtIndex:0] layer] setSpeed:.1f]
into the debugger.
进入调试器。
Thanks to this linkfor the solution.
感谢此链接的解决方案。
回答by JAL
In Swift 3:
在 Swift 3 中:
UIApplication.shared.windows.first?.layer.speed = 0.1
Or, if you're anywhere in your AppDelegate and you only use one window, you can do this:
或者,如果您在 AppDelegate 中的任何位置并且只使用一个窗口,则可以执行以下操作:
window?.layer.speed = 0.1
回答by dreamlab
For SwiftApps:
对于Swift应用程序:
Halt your code with a breakpoint and enter the following lldb command:
使用断点暂停代码并输入以下 lldb 命令:
(lldb)
p UIApplication.sharedApplication().windows.first?.layer.speed = 0.1
(lldb)
p UIApplication.sharedApplication().windows.first?.layer.speed = 0.1
Alternatively you can obviously also change the speed somewhere in you code. For example with an #if
preprocessor macro at application launch
或者,您显然也可以在代码中的某处更改速度。例如#if
在应用程序启动时使用预处理器宏
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
...
#if DEBUG
application.windows.first?.layer.speed = 0.1
#endif
Don't forget to set the DEBUG
symbol in the "Swift Compiler - Custom Flags" section, "Other Swift Flags" line. You add the DEBUG
symbol with a -DDEBUG
entry.
不要忘记DEBUG
在“Swift Compiler - Custom Flags”部分的“Other Swift Flags”行中设置符号。您添加DEBUG
带有-DDEBUG
条目的符号。
回答by Marcos Debastiani
In Objective-c works pretty good
在 Objective-c 中效果很好
self.window.layer.speed = .1f;
回答by Mikael
If you want to slow down the app only in one view controller, you can configure a breakpoint to continue execution after executing the command.
You set this breakpoint in viewDidAppear
.
Then you can set another "non-stoppable" breakpoint to reverse the speed to 1X.
You set this other breakpoint in viewDidDisappear
.
如果您只想在一个视图控制器中减慢应用程序的速度,您可以配置一个断点在执行命令后继续执行。您在viewDidAppear
. 然后你可以设置另一个“不可停止”的断点,将速度反转到 1X。您在viewDidDisappear
.
Very simple. Can be kept in your breakpoint list deactivated and easily reused when needed.
很简单。可以在您的断点列表中保持停用状态,并在需要时轻松重用。