我正在尝试以编程方式创建一个tableview,在tableHeaderView中有一个搜索栏.由于某种原因,搜索栏出现在第一个单元格的顶部.
我正在使用Masonry来构建约束.
有人能指出我做错了什么.
- (void)setupViews {
...
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:self.tableView];
    self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
    self.tableView.tableHeaderView = self.searchBar;
...
}
- (void)updateViewConstraints {
    [self.searchBar mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view);
        make.height.equalTo(@(44));
    }];
    [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.self.top.equalTo(self.view);
        make.self.bottom.equalTo(self.toolbar.mas_top);
        make.width.equalTo(self.view);
    }];
...
}

您可以在此处看到标题与单元格处于同一级别.

我正在尝试Masonry用于iOS.我有一个标签和一个视图.
我想将标签添加到视图中并在视图中水平居中.
但是,我用砌体创建的约束无法正常工作.
UILabel *a = [UILabel new];
a.text = @"Hi";
a.textColor = [UIColor blackColor];
[a sizeToFit];
UIView *b = [UIView new];
b.frame = CGRectMake(0, 0, CGRectGetWidth(a.frame) + 18.0f, 19.0f);
[b addSubview:a];
[a mas_makeConstraints:^(MASConstraintMaker *make) {
    make.centerX.equalTo(b.mas_centerX);
}];
如何使用Masonry正确地将视图置于其中"superview"?
我试图从我的viewController顶部底部动画UIWebView,我正在使用砌体(https://github.com/Masonry/Masonry).
我最初创建了我的webview,其大小为0 - (x,y,height和width),然后我尝试对其进行动画处理,以便webview为viewcontroller的"on top"设置动画.显示了webview,但它没有动画到位 - 它只是立即出现.任何有经验的人都可以指导我朝着正确的方向前进吗?
这是我的按钮动作
-(void)didPressBtn{
    self.infoView = [UIWebView new];
    self.infoView.scalesPageToFit = YES;
    self.infoView.backgroundColor = [UIColor whiteColor];
    self.infoView.delegate = self;
    [self.scrollView addSubview:self.infoView];
    [self.infoView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(0));
    }];
    [self.scrollView layoutIfNeeded];
    //FIXME: Hmmm it doesn't really animate!?
    [UIView animateWithDuration:1 animations:^{
        [self.scrollView setContentOffset:CGPointMake(0, 0)];
        [self.infoView makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.scrollView);
        }];
        [self.scrollView layoutIfNeeded];
    } completion:^(BOOL finished) {
                [self.infoView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:NSLocalizedString(@"INFORMATION_URL", )] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:15]];
    }];
}
我的viewDidLoad
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.scrollView = [UIScrollView new]; …我使用Masonry在代码中创建自动布局约束.
这是我到目前为止:

使用以下代码:
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor whiteColor]];
    UIView *container = [[UIView alloc] init];
    [self.view addSubview:container];
    UIView *itemContainer = [[UIView alloc] init];
    [itemContainer setBackgroundColor:[UIColor colorWithWhite:0.9 alpha:1.0]];
    [container addSubview:itemContainer];
    UIImageView *itemImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Test"]];
    [itemContainer addSubview:itemImage];
    UILabel *itemTitle = [[UILabel alloc] init];
    [itemTitle setNumberOfLines:1];
    [itemTitle setText:@"Lorem ipsum dolor sit amet."];
    [itemTitle setFont:[UIFont boldSystemFontOfSize:12]];
    [itemTitle setTextColor:[UIColor blackColor]];
    [itemContainer addSubview:itemTitle];
    UILabel *itemText = [[UILabel alloc] init];
    [itemText setNumberOfLines:2];
    [itemText setText:@"Lorem ipsum dolor sit amet, consectetur adipiscing …UIButton *testButton = [[UIButton alloc] init];
[self.view addSubview:testButton];
testButton.backgroundColor = [UIColor redColor];
[testButton mas_makeConstraints:^(MASConstraintMaker *make) {
    make.width.equalTo(@100);
    make.height.equalTo(@100);
    make.left.equalTo(self.view.mas_left);
    make.top.equalTo(self.view.mas_top);
}];
[testButton bk_addEventHandler:^(id sender) {
    [self dismissViewControllerAnimated:YES completion:nil];
} forControlEvents:UIControlEventTouchUpInside];
我在代码中使用了BlocksKit和Masonry.如果使用I BlocksKit,bk_addEventHandler则有一个保留周期,我认为这是因为self保留self.view,保留testButton,保留self.但是,当我单独使用Mansonry时没有BlocksKit,并且我在Masonry中使用强自我mas_makeConstraints时,我发现没有保留周期,因为viewController可以调用dealloc方法.任何人都可以向我解释在砌体中没有保留周期吗?