简单的坐标系转移和位置判断

// - 计算point1 是不是在rect1的范围内

    CGRectContainsPoint(rect1, point1)

    

// - 把view1的frame从view1的superView转移到window上边计算就是view1相对于window的坐标

    CGRect newFrame = [view1.superView convertRect:view1.frame toView:nil];

//  -同上

    CGRect newFrame = [view1 convertRect:view1.bounds toView:nil];

 

//  - 因为1中view1的frame 是相对于view1的superview的frame   2中 view1.bounds 是相对于自己的frame  所以两个一样的

 

 

// - 判断某个点是不是在某个 frame 内

    BOOL isInculd =CGRectContainsPoint(rect, point);

 

    // - 返回 rect1 和 rect2 的相交的rect

    CGRect rect = CGRectIntersection(rect1, rect2);

    // - 判断 rect2 和 rect1 是否相交

    BOOL isIntersects = CGRectIntersectsRect(rect1, rect2);

    

    // - 判断rect2 是否包含在 rect1 中

    BOOL isContain = CGRectContainsRect(rect1, rect2);

 

 

CG_EXTERN bool CGPointEqualToPoint(CGPoint point1, CGPoint point2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `size1' and `size2' are the same, false otherwise. */

 

CG_EXTERN bool CGSizeEqualToSize(CGSize size1, CGSize size2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `rect1' and `rect2' are the same, false otherwise. */

 

CG_EXTERN bool CGRectEqualToRect(CGRect rect1, CGRect rect2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Standardize `rect' -- i.e., convert it to an equivalent rect which has

   positive width and height. */

 

CG_EXTERN CGRect CGRectStandardize(CGRect rect)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `rect' is empty (that is, if it has zero width or height),

   false otherwise. A null rect is defined to be empty. */

 

CG_EXTERN bool CGRectIsEmpty(CGRect rect)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `rect' is the null rectangle, false otherwise. */

 

CG_EXTERN bool CGRectIsNull(CGRect rect)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `rect' is the infinite rectangle, false otherwise. */

 

CG_EXTERN bool CGRectIsInfinite(CGRect rect)

    CG_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0);

 

/* Inset `rect' by `(dx, dy)' -- i.e., offset its origin by `(dx, dy)', and

   decrease its size by `(2*dx, 2*dy)'. */

 

CG_EXTERN CGRect CGRectInset(CGRect rect, CGFloat dx, CGFloat dy)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Expand `rect' to the smallest rect containing it with integral origin and

   size. */

 

CG_EXTERN CGRect CGRectIntegral(CGRect rect)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return the union of `r1' and `r2'. */

 

CG_EXTERN CGRect CGRectUnion(CGRect r1, CGRect r2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return the intersection of `r1' and `r2'. This may return a null rect. */

 

CG_EXTERN CGRect CGRectIntersection(CGRect r1, CGRect r2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Offset `rect' by `(dx, dy)'. */

 

CG_EXTERN CGRect CGRectOffset(CGRect rect, CGFloat dx, CGFloat dy)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Make two new rectangles, `slice' and `remainder', by dividing `rect' with

   a line that's parallel to one of its sides, specified by `edge' -- either

   `CGRectMinXEdge', `CGRectMinYEdge', `CGRectMaxXEdge', or

   `CGRectMaxYEdge'. The size of `slice' is determined by `amount', which

   measures the distance from the specified edge. */

 

CG_EXTERN void CGRectDivide(CGRect rect, CGRect *  slice,

    CGRect *  remainder, CGFloat amount, CGRectEdge edge)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `point' is contained in `rect', false otherwise. */

 

CG_EXTERN bool CGRectContainsPoint(CGRect rect, CGPoint point)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `rect2' is contained in `rect1', false otherwise. `rect2'

   is contained in `rect1' if the union of `rect1' and `rect2' is equal to

   `rect1'. */

 

CG_EXTERN bool CGRectContainsRect(CGRect rect1, CGRect rect2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/* Return true if `rect1' intersects `rect2', false otherwise. `rect1'

   intersects `rect2' if the intersection of `rect1' and `rect2' is not the

   null rect. */

 

CG_EXTERN bool CGRectIntersectsRect(CGRect rect1, CGRect rect2)

    CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

 

/*** Persistent representations. ***/

 

/* Return a dictionary representation of `point'. */

 

CG_EXTERN CFDictionaryRef  CGPointCreateDictionaryRepresentation(

    CGPoint point)

    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

 

/* Make a CGPoint from the contents of `dict' (presumably returned earlier

   from `CGPointCreateDictionaryRepresentation') and store the value in

   `point'. Returns true on success; false otherwise. */

 

CG_EXTERN bool CGPointMakeWithDictionaryRepresentation(

    CFDictionaryRef __nullable dict, CGPoint * __nullable point)

    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

 

/* Return a dictionary representation of `size'. */

 

CG_EXTERN CFDictionaryRef  CGSizeCreateDictionaryRepresentation(CGSize size)

    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

 

/* Make a CGSize from the contents of `dict' (presumably returned earlier

   from `CGSizeCreateDictionaryRepresentation') and store the value in

   `size'. Returns true on success; false otherwise. */

 

CG_EXTERN bool CGSizeMakeWithDictionaryRepresentation(

    CFDictionaryRef __nullable dict, CGSize * __nullable size)

    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

 

/* Return a dictionary representation of `rect'. */

 

CG_EXTERN CFDictionaryRef  CGRectCreateDictionaryRepresentation(CGRect)

    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

 

/* Make a CGRect from the contents of `dict' (presumably returned earlier

   from `CGRectCreateDictionaryRepresentation') and store the value in

   `rect'. Returns true on success; false otherwise. */

 

CG_EXTERN bool CGRectMakeWithDictionaryRepresentation(

    CFDictionaryRef __nullable dict, CGRect * __nullable rect)

    CG_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值