Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
Ios UIScrollView作为UIView的子视图不适用于自动布局_Ios_Autolayout_Scrollview_Masonry - Fatal编程技术网

Ios UIScrollView作为UIView的子视图不适用于自动布局

Ios UIScrollView作为UIView的子视图不适用于自动布局,ios,autolayout,scrollview,masonry,Ios,Autolayout,Scrollview,Masonry,我创建了一个customView(UIView),其中包含一个UIScrollView作为其子视图,并且 我放在scrollView上的对象没有显示。为了测试它,我在scrollView中添加了一个UIView,但两个视图都没有显示(参见下面的代码示例)。因为我想放在scrollView上的内容是动态的,所以我想通过使用AutoLayout来解决这个问题。我尝试了不同的方法并在线遵循说明,但没有一个有效,所有类似的问题都是在UIViewController中创建的UIScrollView 这是我

我创建了一个customView(UIView),其中包含一个UIScrollView作为其子视图,并且 我放在scrollView上的对象没有显示。为了测试它,我在scrollView中添加了一个UIView,但两个视图都没有显示(参见下面的代码示例)。因为我想放在scrollView上的内容是动态的,所以我想通过使用AutoLayout来解决这个问题。我尝试了不同的方法并在线遵循说明,但没有一个有效,所有类似的问题都是在UIViewController中创建的UIScrollView

这是我的代码,我使用的是砖石结构:

@interface CustomView : UIView

@end

@implementation CustomView

- (instancetype)init {
    if (self = [super init]) {

        self.scrollView = [[UIScrollView alloc]init];
        self.scrollView.backgroundColor = [UIColor redColor];
        [self addSubview:self.scrollView];
        [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];

    //Here I add someView to the scrollView, and when I create an instance of the scrollView, the someView does not show.

    self.someView = [[UIView alloc]init];
    self.someView.backgroundColor = [UIColor blackColor];
    [self.scrollView addSubview:self.someView];        
    [self.someView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.size.equalTo(CGSizeMake(40, 40));
    }];
}
return self;
}
下面是我如何创建CustomView的实例

CustomView *customView = [[CustomView alloc]init];
[self.view addSubview: customView];
[customView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(64.0);
    make.height.equalTo(40.0);
    make.leading.trailing.equalTo(0);
}];
是否有任何我遗漏或做错的事情导致someView无法显示


感谢您的帮助。

我通过以下方法解决了问题:1)直接使用scrollView,而不是将其作为UIView(我的自定义视图)中的子视图。2) 确保添加scrollView的右侧和底部约束。

您的scrollView是否按预期显示?否则,请检查在设置scrollview和someview约束时是否获得了正确的帧,控制台中是否显示了任何自动布局错误?感谢@pyro提醒我放置断点并检查我的滚动视图,我累了,视图创建正确。一位同事帮我解决了这个错误,他删除了UIView的冗余层,并正确地使用了AutoLayout。