CGRect r1 = CGRectMake(100, 100, 50, 50);
CGRect r3 = CGRectInset(r1, 10, 8);//结果应为:110,108,30,34
/************* 计算工式如下***************
r1.origin.x+=dx;//dx为正数是+=,负数则-=
r1.size.width-=dx*2;
r1.origin.y+=dy;//dy为正数是+=,负数则-=
r1.size.height-=dy*2;
****/
套用结果:
r1.origin.x+=10;//结果为:100+10
r1.size.width-=dx*2;//结果为:50-10*2
r1.origin.y+=dy;//结果为:100+8
r1.size.height-=dy*2;//结果为:50-8*2
//输出结果
NSLog(@"CGRectInset=%@\n",NSStringFromCGRect(r3));
(2)CGRectOffset
CGRect CGRectOffset(
CGRect rect,
CGFloat dx,
CGFloat dy
);
相对于源矩形原点rect(左上角的点)沿x轴和y轴偏移, 再rect基础上沿x轴和y轴偏移
举例如下:
float offset = -50.0;
CGRect r1 = CGRectMake(100, 100, 50, 50);
CGRect r2 = CGRectOffset(r1, offset, offset);
/***
r1.origin.x+=offset;
r1.origin.y+=offset;
***/
NSLog(@"CGRectOffset=%@\n",NSStringFromCGRect(r2));