POPAction.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. Copyright (c) 2014-present, Facebook, Inc.
  3. All rights reserved.
  4. This source code is licensed under the BSD-style license found in the
  5. LICENSE file in the root directory of this source tree. An additional grant
  6. of patent rights can be found in the PATENTS file in the same directory.
  7. */
  8. #ifndef POPACTION_H
  9. #define POPACTION_H
  10. #import <QuartzCore/CATransaction.h>
  11. //#import <pop/POPDefines.h>
  12. #import "POPDefines.h"
  13. #ifdef __cplusplus
  14. namespace POP {
  15. /**
  16. @abstract Disables Core Animation actions using RAII.
  17. @discussion The disablement of actions is scoped to the current transaction.
  18. */
  19. class ActionDisabler
  20. {
  21. BOOL state;
  22. public:
  23. ActionDisabler() POP_NOTHROW
  24. {
  25. state = [CATransaction disableActions];
  26. [CATransaction setDisableActions:YES];
  27. }
  28. ~ActionDisabler()
  29. {
  30. [CATransaction setDisableActions:state];
  31. }
  32. };
  33. /**
  34. @abstract Enables Core Animation actions using RAII.
  35. @discussion The enablement of actions is scoped to the current transaction.
  36. */
  37. class ActionEnabler
  38. {
  39. BOOL state;
  40. public:
  41. ActionEnabler() POP_NOTHROW
  42. {
  43. state = [CATransaction disableActions];
  44. [CATransaction setDisableActions:NO];
  45. }
  46. ~ActionEnabler()
  47. {
  48. [CATransaction setDisableActions:state];
  49. }
  50. };
  51. }
  52. #endif /* __cplusplus */
  53. #endif /* POPACTION_H */