Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 具有相同帧但未完全重叠的两个UIImageView_Iphone_Objective C_Cocoa Touch_Uiimageview - Fatal编程技术网

Iphone 具有相同帧但未完全重叠的两个UIImageView

Iphone 具有相同帧但未完全重叠的两个UIImageView,iphone,objective-c,cocoa-touch,uiimageview,Iphone,Objective C,Cocoa Touch,Uiimageview,第一个UIImageView使用帧(0,38250250)创建,第二个UIImageView使用第一个视图的帧创建,并添加为第一个图像视图的子视图。结果表明,第一个图像视图没有被第二个图像视图完全覆盖。为什么两种观点不重叠?我指定了两个具有不同背景颜色的imageview,以便更容易查看 UIImageView *firstView = [[[UIImageView alloc] initWithFrame:CGRectMake(0,38,250,250)] autorelease]; [fir

第一个UIImageView使用帧(0,38250250)创建,第二个UIImageView使用第一个视图的帧创建,并添加为第一个图像视图的子视图。结果表明,第一个图像视图没有被第二个图像视图完全覆盖。为什么两种观点不重叠?我指定了两个具有不同背景颜色的imageview,以便更容易查看

UIImageView *firstView = [[[UIImageView alloc] initWithFrame:CGRectMake(0,38,250,250)] autorelease];
[firstView setBackgroundColor:RGBACOLOR(36, 39, 39, 0.8)];
[self.view addSubview:firstView];

UIImageView *itemPic = [[[UIImageView alloc] initWithFrame:firstView.frame] autorelease];
itemPic.image = [UIImage imageNamed:@"color_c.png"];
[itemPic setBackgroundColor:RGBACOLOR(150, 150, 35, 0.8)];
[firstView addSubview:itemPic];

子视图被帧的偏移量偏移,您需要
initWithFrame:firstView.bounds
。Bound是一个没有偏移量(原点为0,0)的
CGRect

子视图被帧的偏移量偏移,您需要
initWithFrame:firstView.bounds
。绑定是一个没有偏移(原点为0,0)的
CGRect

如果要将第二个视图添加到第一个视图,则为第二个
CGRectMake(0,0,250,250)创建帧在这种情况下,两个视图将具有相同的坐标


如果要将第二个子视图添加到
self.view
,请使用
firstView.frame
创建它。在这种情况下,两个视图将具有相同的坐标。

如果要将第二个视图添加到第一个视图,请为第二个
CGRectMake(0,0,250,250)创建帧在这种情况下,两个视图将具有相同的坐标


如果要将第二个子视图添加到
self.view
,请使用
firstView.frame
创建它。在这种情况下,两个视图将具有相同的坐标。

帧在不同的坐标系中定义。每个视图的框架都在其父视图的坐标系中定义。该坐标系通常将(0.0,0.0)作为父视图的左上角。框架没有原点(0.0,0.0)的子视图将不会与其父视图对齐

要始终使子视图与其父视图对齐并填充,请使用:

view.frame = parentView.bounds;

框架在不同的坐标系中定义。每个视图的框架都在其父视图的坐标系中定义。该坐标系通常将(0.0,0.0)作为父视图的左上角。框架没有原点(0.0,0.0)的子视图将不会与其父视图对齐

要始终使子视图与其父视图对齐并填充,请使用:

view.frame = parentView.bounds;