Просмотр исходного кода

Add preview image option for CALayer objects

Ryan Olson лет назад: 11
Родитель
Сommit
8f6b8b2dae

+ 13 - 0
Classes/Object Explorers/FLEXLayerExplorerViewController.h

@@ -0,0 +1,13 @@
+//
+//  FLEXLayerExplorerViewController.h
+//  UICatalog
+//
+//  Created by Ryan Olson on 12/14/14.
+//  Copyright (c) 2014 f. All rights reserved.
+//
+
+#import "FLEXObjectExplorerViewController.h"
+
+@interface FLEXLayerExplorerViewController : FLEXObjectExplorerViewController
+
+@end

+ 92 - 0
Classes/Object Explorers/FLEXLayerExplorerViewController.m

@@ -0,0 +1,92 @@
+//
+//  FLEXLayerExplorerViewController.m
+//  UICatalog
+//
+//  Created by Ryan Olson on 12/14/14.
+//  Copyright (c) 2014 f. All rights reserved.
+//
+
+#import "FLEXLayerExplorerViewController.h"
+#import "FLEXImagePreviewViewController.h"
+
+typedef NS_ENUM(NSUInteger, FLEXLayerExplorerRow) {
+    FLEXLayerExplorerRowPreview
+};
+
+@interface FLEXLayerExplorerViewController ()
+
+@property (nonatomic, readonly) CALayer *layerToExplore;
+
+@end
+
+@implementation FLEXLayerExplorerViewController
+
+- (CALayer *)layerToExplore
+{
+    return [self.object isKindOfClass:[CALayer class]] ? self.object : nil;
+}
+
+#pragma mark - Superclass Overrides
+
+- (NSString *)customSectionTitle
+{
+    return @"Shortcuts";
+}
+
+- (NSArray *)customSectionRowCookies
+{
+    return @[@(FLEXLayerExplorerRowPreview)];
+}
+
+- (NSString *)customSectionTitleForRowCookie:(id)rowCookie
+{
+    NSString *title = nil;
+
+    if ([rowCookie isKindOfClass:[NSNumber class]]) {
+        FLEXLayerExplorerRow row = [rowCookie unsignedIntegerValue];
+        switch (row) {
+            case FLEXLayerExplorerRowPreview:
+                title = @"Preview Image";
+                break;
+        }
+    }
+
+    return title;
+}
+
+- (BOOL)customSectionCanDrillIntoRowWithCookie:(id)rowCookie
+{
+    return YES;
+}
+
+- (UIViewController *)customSectionDrillInViewControllerForRowCookie:(id)rowCookie
+{
+    UIViewController *drillInViewController = nil;
+
+    if ([rowCookie isKindOfClass:[NSNumber class]]) {
+        FLEXLayerExplorerRow row = [rowCookie unsignedIntegerValue];
+        switch (row) {
+            case FLEXLayerExplorerRowPreview:
+                drillInViewController = [[self class] imagePreviewViewControllerForLayer:self.layerToExplore];
+                break;
+        }
+    }
+
+    return drillInViewController;
+}
+
++ (UIViewController *)imagePreviewViewControllerForLayer:(CALayer *)layer
+{
+    UIViewController *imagePreviewViewController = nil;
+    if (!CGRectIsEmpty(layer.bounds)) {
+        UIGraphicsBeginImageContextWithOptions(layer.bounds.size, NO, 0.0);
+        CGContextRef imageContext = UIGraphicsGetCurrentContext();
+        [layer renderInContext:imageContext];
+        UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
+        UIGraphicsEndImageContext();
+        imagePreviewViewController = [[FLEXImagePreviewViewController alloc] initWithImage:previewImage];
+    }
+    return imagePreviewViewController;
+}
+
+@end

+ 3 - 1
Classes/Object Explorers/FLEXObjectExplorerFactory.m

@@ -16,6 +16,7 @@
 #import "FLEXViewExplorerViewController.h"
 #import "FLEXViewExplorerViewController.h"
 #import "FLEXImageExplorerViewController.h"
 #import "FLEXImageExplorerViewController.h"
 #import "FLEXClassExplorerViewController.h"
 #import "FLEXClassExplorerViewController.h"
+#import "FLEXLayerExplorerViewController.h"
 #import <objc/runtime.h>
 #import <objc/runtime.h>
 
 
 @implementation FLEXObjectExplorerFactory
 @implementation FLEXObjectExplorerFactory
@@ -36,7 +37,8 @@
                                                    NSStringFromClass([NSUserDefaults class])   : [FLEXDefaultsExplorerViewController class],
                                                    NSStringFromClass([NSUserDefaults class])   : [FLEXDefaultsExplorerViewController class],
                                                    NSStringFromClass([UIViewController class]) : [FLEXViewControllerExplorerViewController class],
                                                    NSStringFromClass([UIViewController class]) : [FLEXViewControllerExplorerViewController class],
                                                    NSStringFromClass([UIView class])           : [FLEXViewExplorerViewController class],
                                                    NSStringFromClass([UIView class])           : [FLEXViewExplorerViewController class],
-                                                   NSStringFromClass([UIImage class])          : [FLEXImageExplorerViewController class]};
+                                                   NSStringFromClass([UIImage class])          : [FLEXImageExplorerViewController class],
+                                                   NSStringFromClass([CALayer class])          : [FLEXLayerExplorerViewController class]};
     });
     });
     
     
     Class explorerClass = nil;
     Class explorerClass = nil;

+ 6 - 0
Example/UICatalog.xcodeproj/project.pbxproj

@@ -91,6 +91,7 @@
 		944F74B5197B458C009AB039 /* FLEXHierarchyTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7484197B458C009AB039 /* FLEXHierarchyTableViewCell.m */; };
 		944F74B5197B458C009AB039 /* FLEXHierarchyTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7484197B458C009AB039 /* FLEXHierarchyTableViewCell.m */; };
 		944F74B6197B458C009AB039 /* FLEXHierarchyTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7486197B458C009AB039 /* FLEXHierarchyTableViewController.m */; };
 		944F74B6197B458C009AB039 /* FLEXHierarchyTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7486197B458C009AB039 /* FLEXHierarchyTableViewController.m */; };
 		944F74B7197B458C009AB039 /* FLEXImagePreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7488197B458C009AB039 /* FLEXImagePreviewViewController.m */; };
 		944F74B7197B458C009AB039 /* FLEXImagePreviewViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7488197B458C009AB039 /* FLEXImagePreviewViewController.m */; };
+		94C681F31A3E941800E1936D /* FLEXLayerExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */; };
 		D03647D919847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */; };
 		D03647D919847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */; };
 /* End PBXBuildFile section */
 /* End PBXBuildFile section */
 
 
@@ -257,6 +258,8 @@
 		944F7486197B458C009AB039 /* FLEXHierarchyTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXHierarchyTableViewController.m; sourceTree = "<group>"; };
 		944F7486197B458C009AB039 /* FLEXHierarchyTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXHierarchyTableViewController.m; sourceTree = "<group>"; };
 		944F7487197B458C009AB039 /* FLEXImagePreviewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXImagePreviewViewController.h; sourceTree = "<group>"; };
 		944F7487197B458C009AB039 /* FLEXImagePreviewViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXImagePreviewViewController.h; sourceTree = "<group>"; };
 		944F7488197B458C009AB039 /* FLEXImagePreviewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXImagePreviewViewController.m; sourceTree = "<group>"; };
 		944F7488197B458C009AB039 /* FLEXImagePreviewViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXImagePreviewViewController.m; sourceTree = "<group>"; };
+		94C681F11A3E941800E1936D /* FLEXLayerExplorerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXLayerExplorerViewController.h; sourceTree = "<group>"; };
+		94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXLayerExplorerViewController.m; sourceTree = "<group>"; };
 		D03647D51984720F007D2A1B /* FLEXManager+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FLEXManager+Private.h"; sourceTree = "<group>"; };
 		D03647D51984720F007D2A1B /* FLEXManager+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FLEXManager+Private.h"; sourceTree = "<group>"; };
 		D03647D719847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXGlobalsTableViewControllerEntry.h; sourceTree = "<group>"; };
 		D03647D719847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXGlobalsTableViewControllerEntry.h; sourceTree = "<group>"; };
 		D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXGlobalsTableViewControllerEntry.m; sourceTree = "<group>"; };
 		D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXGlobalsTableViewControllerEntry.m; sourceTree = "<group>"; };
@@ -448,6 +451,8 @@
 				944F7438197B458C009AB039 /* FLEXViewControllerExplorerViewController.m */,
 				944F7438197B458C009AB039 /* FLEXViewControllerExplorerViewController.m */,
 				944F7439197B458C009AB039 /* FLEXViewExplorerViewController.h */,
 				944F7439197B458C009AB039 /* FLEXViewExplorerViewController.h */,
 				944F743A197B458C009AB039 /* FLEXViewExplorerViewController.m */,
 				944F743A197B458C009AB039 /* FLEXViewExplorerViewController.m */,
+				94C681F11A3E941800E1936D /* FLEXLayerExplorerViewController.h */,
+				94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */,
 				D03647D619847235007D2A1B /* Private */,
 				D03647D619847235007D2A1B /* Private */,
 			);
 			);
 			name = "Object Explorers";
 			name = "Object Explorers";
@@ -706,6 +711,7 @@
 				944F749F197B458C009AB039 /* FLEXArgumentInputSwitchView.m in Sources */,
 				944F749F197B458C009AB039 /* FLEXArgumentInputSwitchView.m in Sources */,
 				944F74A3197B458C009AB039 /* FLEXDefaultEditorViewController.m in Sources */,
 				944F74A3197B458C009AB039 /* FLEXDefaultEditorViewController.m in Sources */,
 				944F74AB197B458C009AB039 /* FLEXManager.m in Sources */,
 				944F74AB197B458C009AB039 /* FLEXManager.m in Sources */,
+				94C681F31A3E941800E1936D /* FLEXLayerExplorerViewController.m in Sources */,
 				944F74B2197B458C009AB039 /* FLEXLibrariesTableViewController.m in Sources */,
 				944F74B2197B458C009AB039 /* FLEXLibrariesTableViewController.m in Sources */,
 				535682BF18F3670300BAAD62 /* UIColor+AAPLApplicationSpecific.m in Sources */,
 				535682BF18F3670300BAAD62 /* UIColor+AAPLApplicationSpecific.m in Sources */,
 				535682B718F3670300BAAD62 /* AAPLSliderViewController.m in Sources */,
 				535682B718F3670300BAAD62 /* AAPLSliderViewController.m in Sources */,