IOS-frame和bounds小识

概念

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好友一起讨论;(* ̄︶ ̄)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值