Detect if slow animations is on / off in iOS Simulator in code
Fortunately it's easy:
float UIAnimationDragCoefficient(void);static inline BOOL slowAnimationsEnabled(){#if TARGET_IPHONE_SIMULATOR return UIAnimationDragCoefficient() != 1;#else return NO;#endif}
I defined this function that returns the factor to multiply animation durations with (1 if slow animations are disabled, the slowness factor otherwise):
CGFloat FTSimulatorAnimationDragCoefficient(void) { static float (*UIAnimationDragCoefficient)(void) = NULL;#if TARGET_IPHONE_SIMULATOR static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ UIAnimationDragCoefficient = (float (*)(void))dlsym(RTLD_DEFAULT, "UIAnimationDragCoefficient"); });#endif return UIAnimationDragCoefficient ? UIAnimationDragCoefficient() : 1.f;}
Note that I use float
, not CGFloat
as the return type of the called UIAnimationDragCoefficient()
function. This is needed to work with the 64 bit simulator.
Then I can simply multiply the animation duration:
CAAnimation animation = [CABasicAnimation animation];animation.duration = 0.5 * FTSimulatorAnimationDragCoefficient();