Last active
June 14, 2018 08:32
-
-
Save acalism/d4414af29e55dbc6fc778aecfbb8bdd7 to your computer and use it in GitHub Desktop.
Revisions
-
acalism revised this gist
Jun 14, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,9 +26,12 @@ - (void)viewDidLoad { _label.text = @"hey"; [_v addSubview:_label]; // Do NOT add any constraint at here, or else `updateViewController` will be called twice. // IMPORTANT: 否则updateViewConstraints不被执行 self.view.translatesAutoresizingMaskIntoConstraints = false; //[self.view setNeedsUpdateConstraints]; // another method, but it trigger -[UIViewController updateViewConstraints] executed twice //[self.view setNeedsLayout]; // useless code } -
acalism revised this gist
Jun 14, 2018 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ #import <Masonry/Masonry.h> @implementation ViewController { UIView * _v; UILabel * _label; -
acalism revised this gist
Jun 14, 2018 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,9 +23,10 @@ - (void)viewDidLoad { _label.text = @"hey"; [_v addSubview:_label]; // IMPORTANT: 否则updateViewConstraints不被执行 self.view.translatesAutoresizingMaskIntoConstraints = false; //[self.view setNeedsUpdateConstraints]; // another method, but it trigger -[UIViewController updateViewConstraints] executed twice //[self.view setNeedsLayout]; // useless code } - (void)updateViewConstraints { -
acalism revised this gist
Jun 14, 2018 . 1 changed file with 13 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ @implementation ViewController { UIView * _v; UILabel * _label; bool _constraintsAdded; } - (void)viewDidLoad { @@ -27,13 +29,17 @@ - (void)viewDidLoad { } - (void)updateViewConstraints { if (!_constraintsAdded) { _constraintsAdded = true; [_v mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(100, 50, 200, 30)); }]; [_label mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(_v); }]; } NSLog(@"update constraint."); [super updateViewConstraints]; -
acalism created this gist
Jun 13, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ @implementation ViewController { UIView * _v; UILabel * _label; } - (void)viewDidLoad { [super viewDidLoad]; UILabel *l = [UILabel new]; l.text = @"我能优先显示吗?"; l.tintColor = [UIColor magentaColor]; l.frame = CGRectMake(100, 50, 160, 20); [self.view addSubview:l]; _v = UIView.new; _v.backgroundColor = [UIColor greenColor]; [self.view addSubview:_v]; _label = UILabel.new; _label.tintColor = [UIColor redColor]; _label.text = @"hey"; [_v addSubview:_label]; self.view.translatesAutoresizingMaskIntoConstraints = false; //[self.view setNeedsUpdateConstraints]; //[self.view setNeedsLayout]; } - (void)updateViewConstraints { [_v mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(100, 50, 200, 30)); }]; [_label mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(_v); }]; NSLog(@"update constraint."); [super updateViewConstraints]; } @end