Ver código fonte

Add hack to FLEXRuntimeUtility to add a frame property on UIView.

Despite being declared as a property in UIView.h, frame is not a property from the perspective of the runtime. In order to easily use our property editing interface for viewing and changing view frames, we add the frame property to the UIView class at runtime if it doesn’t already exist.
Ryan Olson 12 anos atrás
pai
commit
47d3990f4a

+ 1 - 0
Classes/Utility/FLEXRuntimeUtility.h

@@ -21,6 +21,7 @@ extern const unsigned int kFLEXNumberOfImplicitArgs;
 + (NSString *)fullDescriptionForProperty:(objc_property_t)property;
 + (id)valueForProperty:(objc_property_t)property onObject:(id)object;
 + (NSString *)descriptionForIvarOrPropertyValue:(id)value;
++ (void)addFramePropertyToUIViewIfNeeded;
 
 // Ivar Helpers
 + (NSString *)prettyNameForIvar:(Ivar)ivar;

+ 17 - 0
Classes/Utility/FLEXRuntimeUtility.m

@@ -162,6 +162,23 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
     return description;
 }
 
++ (void)addFramePropertyToUIViewIfNeeded
+{
+    const char *framePropertyName = "frame";
+    objc_property_t frameProperty = class_getProperty([UIView class], framePropertyName);
+    if (!frameProperty) {
+        objc_property_attribute_t typeAttribute;
+        typeAttribute.name = [kFLEXUtilityAttributeTypeEncoding UTF8String];
+        typeAttribute.value = @encode(CGRect);
+        objc_property_attribute_t nonatomicAttribute;
+        nonatomicAttribute.name = [kFLEXUtilityAttributeNonAtomic UTF8String];
+        nonatomicAttribute.value = "";
+        const unsigned int kAttributeCount = 2;
+        objc_property_attribute_t attributes[kAttributeCount] = {typeAttribute, nonatomicAttribute};
+        class_addProperty([UIView class], framePropertyName, attributes, kAttributeCount);
+    }
+}
+
 
 #pragma mark - Ivar Helpers (Public)