You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.3 KiB

  1. //
  2. // FLEXLayerExplorerViewController.m
  3. // FLEX
  4. //
  5. // Created by Ryan Olson on 12/14/14.
  6. // Copyright (c) 2014 f. All rights reserved.
  7. //
  8. #import "FLEXLayerExplorerViewController.h"
  9. #import "FLEXImagePreviewViewController.h"
  10. typedef NS_ENUM(NSUInteger, FLEXLayerExplorerRow) {
  11. FLEXLayerExplorerRowPreview
  12. };
  13. @interface FLEXLayerExplorerViewController ()
  14. @property (nonatomic, readonly) CALayer *layerToExplore;
  15. @end
  16. @implementation FLEXLayerExplorerViewController
  17. - (CALayer *)layerToExplore
  18. {
  19. return [self.object isKindOfClass:[CALayer class]] ? self.object : nil;
  20. }
  21. #pragma mark - Superclass Overrides
  22. - (NSString *)customSectionTitle
  23. {
  24. return @"Shortcuts";
  25. }
  26. - (NSArray *)customSectionRowCookies
  27. {
  28. return @[@(FLEXLayerExplorerRowPreview)];
  29. }
  30. - (NSString *)customSectionTitleForRowCookie:(id)rowCookie
  31. {
  32. NSString *title = nil;
  33. if ([rowCookie isKindOfClass:[NSNumber class]]) {
  34. FLEXLayerExplorerRow row = [rowCookie unsignedIntegerValue];
  35. switch (row) {
  36. case FLEXLayerExplorerRowPreview:
  37. title = @"Preview Image";
  38. break;
  39. }
  40. }
  41. return title;
  42. }
  43. - (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
  44. {
  45. UIViewController *drillInViewController = nil;
  46. if ([rowCookie isKindOfClass:[NSNumber class]]) {
  47. FLEXLayerExplorerRow row = [rowCookie unsignedIntegerValue];
  48. switch (row) {
  49. case FLEXLayerExplorerRowPreview:
  50. drillInViewController = [[self class] imagePreviewViewControllerForLayer:self.layerToExplore];
  51. break;
  52. }
  53. }
  54. return drillInViewController;
  55. }
  56. + (UIViewController *)imagePreviewViewControllerForLayer:(CALayer *)layer
  57. {
  58. UIViewController *imagePreviewViewController = nil;
  59. if (!CGRectIsEmpty(layer.bounds)) {
  60. UIGraphicsBeginImageContextWithOptions(layer.bounds.size, NO, 0.0);
  61. CGContextRef imageContext = UIGraphicsGetCurrentContext();
  62. [layer renderInContext:imageContext];
  63. UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
  64. UIGraphicsEndImageContext();
  65. imagePreviewViewController = [[FLEXImagePreviewViewController alloc] initWithImage:previewImage];
  66. }
  67. return imagePreviewViewController;
  68. }
  69. @end