c - 罕见的创建视图的方法,求指教
怪我咯
怪我咯 2017-05-02 09:29:47
0
1
456

创建视图的方法,但是很诡异,看不懂是什么意思,求大神指教

代码如下:

 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;
                });
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
習慣沉默

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template