CGRect延伸

判断给定的点是否被一个CGRect包含,可以用CGRectContainsPoint函数

BOOLcontains=CGRectContainsPoint(CGRectrect,CGPointpoint);

判断一个CGRect是否包含再另一个CGRect里面,常用与测试给定的对象之间是否又重叠

BOOLcontains =CGRectContainsRect(CGRectrect1,CGRectrect2);

判断两个结构体是否有交错.可以用CGRectIntersectsRect

BOOLcontains =CGRectIntersectsRect(CGRectrect1,CGRectrect2);

floatfloat_ =CGRectGetMaxX(CGRectrect);返回矩形右边缘的坐标

CGRectGetMinY返回矩形顶部的坐标

CGRectGetMidX返回矩形中心X的坐标

CGRectGetMidY返回矩形中心Y的坐标

CGRectGetMinX 返回矩形左边缘的坐标

CGRectGetMaxY返回矩形底部的坐标

CGRectInset((cgrect)(例如:fram.bouns), (float)a, (float)b;//将一个矩形上下a,左右加边界b;返回值是一个cgrect

CGRectOffset((cgrect), (float)a, (float)b);//作用将一个方框向左a向下b移动一定距离,产生一个新的方框

 

 

还有就是需要定义一些 策略    示例代码

#import <UIKit/UIKit.h> 

@interface UIView (Frame) 

@property (nonatomic, assign) CGFloat x; 

@property (nonatomic, assign) CGFloat y; 

@property (nonatomic, assign) CGFloat width; 

@property (nonatomic, assign) CGFloat height; 

@property (nonatomic, assign) CGPoint origin; 

@property (nonatomic, assign) CGSize size; @end

 

#import "UIView+Frame.h" 

@implementation UIView (Frame) 

- (void)setX:(CGFloat)x {

CGRect frame = self.frame; 

frame.origin.x = x; 

self.frame = frame; 

- (CGFloat)x { 

return self.frame.origin.x;

- (void)setY:(CGFloat)y { 

CGRect frame = self.frame; 

frame.origin.y = y; 

self.frame = frame; 

}

- (CGFloat)y { return self.frame.origin.y; } 

- (void)setWidth:(CGFloat)width { CGRect frame = self.frame; frame.size.width = width; self.frame = frame; } 

- (CGFloat)width { return self.frame.size.width; } 

- (void)setHeight:(CGFloat)height { CGRect frame = self.frame; frame.size.height = height; self.frame = frame; } 

- (CGFloat)height { return self.frame.size.height; } 

- (void)setOrigin:(CGPoint)origin { CGRect frame = self.frame; frame.origin = origin; self.frame = frame; } 

- (CGPoint)origin { return self.frame.origin; } 

-(void)setSize:(CGSize)size { CGRect frame = self.frame; frame.size = size; self.frame = frame; } 

-(CGSize)size { return self.frame.size; } 

@end

还可以扩展  bottom top 等

 

这样写了之后,工程里用的就很方便啦

posted on 2016-04-05 23:14  &#127774;Bob  阅读(311)  评论(0编辑  收藏  举报

导航