创建视图的方法,但是很诡异,看不懂是什么意思,求大神指教
代码如下:
UIView *cancel = ({
UIButton *view= [UIButton new];
view.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
[view setTitle:NSLocalizedString(@"cancel", nil) forState:UIControlStateNormal];
[view setTitleColor:Global_trelloBlue forState:UIControlStateNormal];
view.titleLabel.font = [UIFont systemFontOfSize:15];
[createListView addSubview:view];
view.tag = 999;
[view makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(20);
make.bottom.equalTo(-1);
make.width.equalTo(100);
}];
[view sizeToFit];
view.alpha = 0;
[self layoutIfNeeded];
//cancel点击事件
@weakify(self, view, textView, createListView, listView, add, addCard)
[[view rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
@strongify(self, view, textView, createListView, listView, add, addCard)
//footer高度还原
[createListView updateConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(44);
}];
//list减去footer增加的高度(在这里做是为了动效)
[listView updateConstraints:^(MASConstraintMaker *make) {
make.height.equalTo(listView.yyHeight-44);
}];
//隐藏textView
textView.alpha = 0;
[UIView animateWithDuration:0.25 animations:^{
//cancel隐藏
view.alpha = 0;
//add隐藏
add.alpha = 0;
//addCard显示
addCard.alpha = 1;
[self.viewController.navigationController setNavigationBarHidden:NO animated:YES];
[self layoutIfNeeded];
}];
[textView resignFirstResponder];
}];
view;
});
Is it weird? This is what I copied...
The parameters of addSubview are placed in a "({})" code block, and the creation and attribute setting of the view are completed in "({})". The code block is at the end One sentence is the subview we want to add.
This writing method follows a feature of GNU C, namely compound statement. That is, in the "({})" code block, we can place multiple statements, which can be loops, branches, variable declarations, function calls, etc. The last sentence of a compound statement is an expression, which serves as the final value of the entire compound statement.
When writing Objective-C code, using compound statements can make our code more elegant, especially when creating and adding a bunch of subviews, it can make our code look cleaner. Recommended for regular use.
Webpage