概念
frame 是相对于父组件的坐标位置 ;即参照物为父组件,以父组件的左上方为原点的坐标系;
bounds 是以组件本身为参照物的位置;例如 组件本身的左上角即为当前坐标系的原点;
例子
测试代码
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *vc = [[UIViewController alloc]init];
self.window.rootViewController = vc;
self.window.backgroundColor = [UIColor grayColor];
UIView *uiv_one = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
uiv_one.backgroundColor = [UIColor blueColor];
uiv_one.bounds = CGRectMake(-20, -20, 100, 100);
[self.window addSubview:uiv_one];
UIView *uiv_two = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
uiv_two.backgroundColor = [UIColor redColor];
[uiv_one addSubview:uiv_two];
[self.window makeKeyAndVisible];
return YES;
}
@end
效果截图
备注
这里的uiv_two 的位置为 x = 0 - (-20), y = 0 - (-20),所以他的位置为截图位置;
有兴趣的小伙伴可以加我qq好友一起讨论;(* ̄︶ ̄)