Key - value coding extension

Key - value coding extension

CoreAnimationIt extends the NSKeyValueCodingprotocol because it is dependent CAAnimation, and CALayerclass. This extension add some keys default encapsulation extended agreement for CGPoint, CGRect, CGSize, CATransform3Dadd key path support

Key - value coding compliant container class

CAAnimationAnd the CALayerclass is a container class key compliance - value coding, i.e. the set value can be any key. Even if the key is not in CALayerthe properties declared in the class, you can also set the value in the following manner

[theLayer setValue: @50 forKey: @"someKey"];

You can also get the value corresponding to any key, other keys as to obtain the value corresponding to the same path. as follows

someKeyValue = [theLayer valueForKey: @"someKey"];

Support default values

CoreAnimationA bond - to add a value coding conventions, i.e., a class can provide a default value for a key, without the set value. CAAnimationAnd CALayerclasses support this convention, through the use of defaultValueForKey:class methods. Provide default values for a key, expectations need to create a subclass of class, while complying with defaultValueForKey:class methods. Implementation of this method to check the key parameter and return appropriate default values. The following example

+ (id)defaultValueForKey:(NSString *)key {
	if ([key isEqualToString: @"maskToBounds"]) {
		return @(YES);
	}
	return [super defaultValueForKey: key];
}

Package agreed

C language type Package Type
CGPoint NSValue
cgsiz to NSValue
CGRect NSValue
CATransform3D NSValue
CGAffineTransform NSAffineTransform(OS X only)

Key path support structure

CAAnimationAnd CALayerclasses allow access path using the key fields of data structure. This feature is more convenient to specify the structure of the field to get the movie you want. By setValue: forKeyPath:setting and valueForKeyPath:get

[myLayer setValue: @10.0 forKeyPath: @"transform.translation.x"];
  • CATransform3D Critical Path
Key path field description
rotation.x NSNumber object is disposed, X radians is rotated
rotation.y NSNumber object is disposed, Y rotated radians
rotation.z NSNumber object is provided, Z radians is rotated
rotation Set NSNumber objects, with the same effect rotation.z
scale.x NSNumber object is disposed, X stretching factor
scale.y NSNumber object is disposed, Y stretching factor
scale.z NSNumber object is provided, Z stretching factor
scale NSNumber object is provided, three-directional stretch factor
translation.x NSNumber object is disposed, X direction movement value
translation.y NSNumber object is disposed, Y values ​​to the mobile
translation.z NSNumber object is provided, Z value to the mobile
translation NSValue provided object (or CGSize comprising NSSize data types), X and Y values ​​to the mobile
  • CGPoint Critical Path
Structure fields description
x X value of the point
Y Y value of the point
  • CGSize Critical Path
Structure fields description
width width
height high
  • CGRect Critical Path
Structure fields description
origin point
origin.x X value
origin.y Y value
size size
size.width width
size.height high

Guess you like

Origin www.cnblogs.com/tzsh1007/p/12427857.html