UIGeometry - 几何

2016-04-06  本文已影响254人  居然是村长

UIEdgeInsets 内嵌

    /*
     typedef struct UIEdgeInsets {
     CGFloat top, left, bottom, right;
     } UIEdgeInsets;
     */

    UIEdgeInsets edgInset = UIEdgeInsetsMake(10, 20, 30, 40);
    UIEdgeInsets zeroEdgInset = UIEdgeInsetsZero;
    CGRect insetRect = UIEdgeInsetsInsetRect(rect, edgInset);

    BOOL isequalEdg = UIEdgeInsetsEqualToEdgeInsets(edgInset, edgInset);

UIOffset 偏移

    /*
     typedef struct UIOffset {
     CGFloat horizontal, vertical;
     } UIOffset;
     */

    UIOffset offset = UIOffsetMake(100, 200);
    UIOffset zeroOffset = UIOffsetZero;

    BOOL isOffset = UIOffsetEqualToOffset(offset, offset);

Value 转换 (拓展)

    CGPoint point = CGPointMake(100, 100);
    CGSize size = CGSizeMake(100, 200);
    CGRect rect = CGRectMake(100, 100, 100, 100);
    
    CGVector vector = CGVectorMake(10, 20);
    CGAffineTransform transform = CGAffineTransformMake(10, 20, 30, 40, 50, 60);
    
    UIEdgeInsets edgInset = UIEdgeInsetsMake(10, 20, 30, 40);
    UIOffset offset = UIOffsetMake(100, 200);
    NSValue *pointValue = [NSValue valueWithCGPoint:point];
    NSValue *sizeValue = [NSValue valueWithCGSize:size];
    NSValue *rectValue = [NSValue valueWithCGRect:rect];

    NSValue *vectorValue = [NSValue valueWithCGVector:vector];
    NSValue *transformValue = [NSValue valueWithCGAffineTransform:transform];

    NSValue *edgInsetValue = [NSValue valueWithUIEdgeInsets:edgInset];
    NSValue *offsetValue = [NSValue valueWithUIOffset:offset];
    CGPoint point1 = [pointValue CGPointValue];;
    CGSize size1 = [sizeValue CGSizeValue];
    CGRect rect1 = [rectValue CGRectValue];
    
    CGVector vector1 = [vectorValue CGVectorValue];;
    CGAffineTransform transform1 = [transformValue CGAffineTransformValue];
    
    UIEdgeInsets edgInset1 = [edgInsetValue UIEdgeInsetsValue];
    UIOffset offset1 = [offsetValue UIOffsetValue];

NSString 互相 转换

    NSString *pointString = NSStringFromCGPoint(point);
    NSString *sizeString = NSStringFromCGSize(size);
    NSString *rectString = NSStringFromCGRect(rect);
    
    NSString *vectorString = NSStringFromCGVector(vector);
    NSString *transformString = NSStringFromCGAffineTransform(transform);
    
    NSString *edgInsetString = NSStringFromUIEdgeInsets(edgInset);
    NSString *offsetString = NSStringFromUIOffset(offset);
    CGPoint point1 = CGPointFromString(pointString);
    CGSize size1 = CGSizeFromString(sizeString);
    CGRect rect1 = CGRectFromString(rectString);
    
    CGVector vector1 = CGVectorFromString(vectorString);
    CGAffineTransform transform1 = CGAffineTransformFromString(transformString);
    
    UIEdgeInsets edgInset1 = UIEdgeInsetsFromString(edgInsetString);
    UIOffset offset1 = UIOffsetFromString(offsetString);

其他


@interface NSCoder (UIGeometryKeyedCoding)

- (void)encodeCGPoint:(CGPoint)point forKey:(NSString *)key;
- (void)encodeCGVector:(CGVector)vector forKey:(NSString *)key;
- (void)encodeCGSize:(CGSize)size forKey:(NSString *)key;
- (void)encodeCGRect:(CGRect)rect forKey:(NSString *)key;
- (void)encodeCGAffineTransform:(CGAffineTransform)transform forKey:(NSString *)key;
- (void)encodeUIEdgeInsets:(UIEdgeInsets)insets forKey:(NSString *)key;
- (void)encodeUIOffset:(UIOffset)offset forKey:(NSString *)key NS_AVAILABLE_IOS(5_0);

- (CGPoint)decodeCGPointForKey:(NSString *)key;
- (CGVector)decodeCGVectorForKey:(NSString *)key;
- (CGSize)decodeCGSizeForKey:(NSString *)key;
- (CGRect)decodeCGRectForKey:(NSString *)key;
- (CGAffineTransform)decodeCGAffineTransformForKey:(NSString *)key;
- (UIEdgeInsets)decodeUIEdgeInsetsForKey:(NSString *)key;
- (UIOffset)decodeUIOffsetForKey:(NSString *)key NS_AVAILABLE_IOS(5_0);

@end

1

上一篇下一篇

猜你喜欢

热点阅读