关于数组中加入相同的view的试验
随便新建一个工程,然后在控制器中粘贴如下代码
- (void)viewDidLoad {
[super viewDidLoad];
UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
view.backgroundColor = [UIColor greenColor];
NSArray * arr = [[NSArray alloc]initWithObjects:view, view, nil];
NSLog(@"====-----%@",arr);
UIView * view1 = arr[0];
view1.frame = CGRectMake(0, 100, 100, 100);
[self.view addSubview:view1];
UIView * view2 = arr[1];
view2.frame = CGRectMake(0, 100, 20, 20);
[self.view addSubview:view2];
UIView * view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
view3.backgroundColor = [UIColor blueColor];
[self.view addSubview:view3];
UIView * view4 = [[UIView alloc]initWithFrame:CGRectMake(0, 300, 200, 200)];
view4.backgroundColor = [UIColor redColor];
[self.view addSubview:view4];
// [view3 addSubview:view1];
// [view3 addSubview:view2];
//一个view 只能加到最后一个 父控件上
[view4 addSubview:view2];
[view3 addSubview:view1];
}
运行后 的打印如下
====-----(
"<UIView: 0x7fc8cdd01760; frame = (0 0; 100 100); layer = <CALayer: 0x600001cacfa0>>",
"<UIView: 0x7fc8cdd01760; frame = (0 0; 100 100); layer = <CALayer: 0x600001cacfa0>>"
)
也就是说 虽然 数组中有两个元素 但是两个元素的地址 全都指向了同一块内存 也就是 view所在的内存。
简单理解为 数组存了 这个view对象的 指针, 通过 arr[0] 和 arr[1]拿到的都是同一个view。
所以最后 加到view3 上一个view 加到view4上一个view 加的都是同一个。 而同一个view只能加到一个superview上 ,之前加的自动失效 或者可以理解为 自动被remove后 然后 加到新的 superView上。所以运行模拟器 就有了 一下的现象

关于数组中加入相同的view的试验的更多相关文章
- Vue 改变数组中对象的属性不重新渲染View的解决方案
Vue 改变数组中对象的属性不重新渲染View的解决方案 在解决问题之前,我们先来了解下 vue响应性原理: Vue最显著的一个功能是响应系统-- 模型只是一个普通对象,修改对象则会更新视图.受到ja ...
- Android中自定义样式与View的构造函数中的第三个参数defStyle的意义
零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...
- 解析plist文件(字典里包着数组,数组中又包含字典)
#import "RootTableViewController.h" #import "City.h" @interface RootTableViewCon ...
- php从数组中取出一段 之 array_slice
array array_slice ( array $array , int $offset [, int $length [, bool $preserve_keys ]] ) array_slic ...
- js从数组中随机取出不同的元素
前言 上午处理个需求需要从一个总数组中随机取出不同的元素.共使用两个方法.第一种方法较常规,经测试有bug,数据量大以后随机几次返回的对象直接是function而不是object. 当然简单数据类型应 ...
- [LeetCode] Find All Numbers Disappeared in an Array 找出数组中所有消失的数字
Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and ot ...
- [LeetCode] Find All Duplicates in an Array 找出数组中所有重复项
Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others ...
- [LeetCode] Kth Largest Element in an Array 数组中第k大的数字
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...
- [LeetCode] Search in Rotated Sorted Array II 在旋转有序数组中搜索之二
Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed? Would this ...
随机推荐
- 【递推】【推导】【乘法逆元】UVA - 11174 - Stand in a Line
http://blog.csdn.net/u011915301/article/details/43883039 依旧是<训练指南>上的一道例题.书上讲的比较抽象,下面就把解法具体一下.因 ...
- python基础之文件操作,函数
文件操作 +模式: r+t w+t a+t r+b w+b a+b 可读可写,其他功能与人,r,w,a相同 f.seek(offset,whence) 文件指针移动 offest的单 ...
- Java高级架构师(一)第35节:Nginx的Location区段
没有修饰符 表示:必须以指定模式开始. 表示/abc下的所有内容都可以被访问. = 表示与指定的模式精确匹配,可以带参数. 实例中要求区分大小写,并以c结尾. 实例中指定的正则表达式不区分大小写. 注 ...
- ucenter创始人密码忘记了,修改方法
简单的:1.在UCenter/data/下找到config.inc.php,打开找到下面2行代码: define('UC_FOUNDERPW', '3858cdf66b0794bfd435af8c0c ...
- subline text 工具快捷键说明
编辑 ctrl + enter 光标当前行下一行新增一行,并且光标跳到下一行进行编辑 ctrl + shift +enter 光标当前行上一行新增一行,并且光标跳到上一行进行编辑 ...
- IP编址
IP地址 /include/linux/inetdevice.h,定义IPV4专用的网络设备相关的结构.宏等 /net/ipv4/devinet.c.支持IPV4特性的设备操作接口 数据组织 net_ ...
- RawCap抓取本地回环接口数据包
RawCap.exe --help ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 D: ...
- python wheel 包命名规则和 abi 兼容
wheel 包的命名规定 wheel 包的命名格式为 {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform ...
- Linux驱动虚拟地址和物理地址的映射
一般情况下,Linux系统中,进程的4GB内存空间被划分成为两个部分------用户空间和内核空间,大小分别为0~3G,3~4G. 用户进程通常情况下,只能访问用户空间的虚拟地址,不能访问到内核空间. ...
- Log文件太大,手机ROM空间被占满
客户要装车,进行项目验收了. 今天拿着几台手机去客户处,其中有一台手机从昨天晚上开始就一直开着我们的APP,今天早晨打开手机发现APP没有反应了. 在程序列表中将其杀掉,然后再启动程序,发现程序不能启 ...