Ios 如何将正确的框架设置为自定义视图?
我正在向用户控制器添加自定义视图(Ios 如何将正确的框架设置为自定义视图?,ios,Ios,我正在向用户控制器添加自定义视图(MainComponentView)。现在在MainComponentView中,我还添加了一个自定义视图(FirstPartView),并且FirstPartView的高度应该小于MainComponentView的高度。我的问题是,当我给MainComponentView的高度小于FirstPartViewheight时,它仍然显示FirstPartView的整个视图 // MainComponentView self.aComponent = [[Main
MainComponentView
)。现在在MainComponentView
中,我还添加了一个自定义视图(FirstPartView
),并且FirstPartView
的高度应该小于MainComponentView
的高度。我的问题是,当我给MainComponentView
的高度小于FirstPartView
height时,它仍然显示FirstPartView
的整个视图
// MainComponentView
self.aComponent = [[MainComponentView alloc] initWithFrame:CGRectMake(212, 0, 600, 550)
withStartDate:startDate
endDate:endDate];
[self.view addSubview:self.aComponent];
要将自定义视图添加到MainComponentView
:
self.aFirPartView = [[FirPartView alloc] initWithFrame:CGRectMake(0, self.frame.origin.y, self.frame.size.width, HEIGHT_OF_COMPONENT1) withStartDate:startDate endDate:endDate];
[self addSubview:self.aFirPartView];`
尝试:
告诉视图不应绘制其框架之外的任何子视图的任何部分。子视图坐标相对于superview,而不是相对于窗口,因此执行此操作时:
self.aFirPartView = [[FirPartView alloc] initWithFrame:CGRectMake(0, self.frame.origin.y, self.frame.size.width, HEIGHT_OF_COMPONENT1) withStartDate:startDate endDate:endDate];
[self addSubview:self.aFirPartView];`
您创建的视图向下偏移MainComponentView
与屏幕顶部的距离
请尝试改用此帧值:
CGRectMake(0, 0, self.bounds.size.width, HEIGHT_OF_COMPONENT1)
这将子视图定位在
main组件视图的左上角,具有指定的宽度和高度。哦,是的!!!一分钟…..添加MainComponentView:self.acComponent=[[MainComponentView alloc]initWithFrame:CGRectMake(212,0600550),起始日期:startDate endDate:endDate];[self.view addSubview:self.aComponent];并在MainComponentView中添加自定义视图:self.aFirPartView=[[FirPartView alloc]initWithFrame:CGRectMake(0,self.frame.origin.y,self.frame.size.width,HEIGHT_OF_COMPONENT1),起始日期:startDate-endDate:endDate];[self addSubview:self.aFirPartView];请编辑问题并粘贴到那里。“像这样理解太难了!”德斯德诺娃和桑尼:请帮帮我或给我任何提示。。。
CGRectMake(0, 0, self.bounds.size.width, HEIGHT_OF_COMPONENT1)