tomknig / TOMSMorphingLabel

Configurable morphing transitions between text values of a label.
MIT License
1.86k stars 104 forks source link

Respect global [UIView areAnimationsEnabled] state. #20

Closed wanderwaltz closed 9 years ago

wanderwaltz commented 9 years ago

Hi! I suppose TOMSMorphingLabel should also respect the global areAnimationsEnabled flag of the UIView class so that setting the text like this:

[UIView performWithoutAnimation: ^{
     tomsLabel.text = @"new text";
}];

will actually set the text without animation as expected.

The same goes for the following:

[UIView setAnimationsEnabled: NO];
tomsLabel.text = @"new text";

As per documentation for setAnimationsEnabled:, if we disable animations, the currently running animation blocks will continue, but subsequent animation blocks will perform without animation. So checking the [UIView areAnimationsEnabled] state in the isMorphingEnabled getter seems reasonable enough - it won't affect the already started animations but will prevent new ones to start.

wanderwaltz commented 9 years ago

As I keep thinking about it, checking [UIView areAnimationsEnabled] inside the isMorphingEnabled getter is actually a bad idea. We expect the property value returned by the getter to correspond to the values we set using the setter. So we want the following to be true in any case:

tomsLabel.morphingEnabled = YES;
NSAssert(tomsLabel.morphingEnabled, @"property should return the value we've just set");

But if the getter would also check areAnimationsEnabled, this code would not work inside the performWithoutAnimation: block for example.

So I've created a separate method which is used to check both of the property value and the UIView flag.

tomknig commented 9 years ago

Hi Egor,

I do also agree with this one. You are awesome! Thank you again, Tom

wanderwaltz commented 9 years ago

Thanks! :+1: