And*_*win 1 objective-c ios objective-c-blocks masonry-ios-osx
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];
Run Code Online (Sandbox Code Playgroud)
我在代码中使用了BlocksKit和Masonry.如果使用I BlocksKit,bk_addEventHandler则有一个保留周期,我认为这是因为self保留self.view,保留testButton,保留self.但是,当我单独使用Mansonry时没有BlocksKit,并且我在Masonry中使用强自我mas_makeConstraints时,我发现没有保留周期,因为viewController可以调用dealloc方法.任何人都可以向我解释在砌体中没有保留周期吗?
这是因为块工具块块被保留以便以后执行(因此创建,通过对self的引用,保留周期),而砌体块现在或多或少地执行然后被丢弃.
同样,在调用UIView animate...方法时,您永远不必担心保留周期.这是因为一旦你的代码结束,运行循环结束,动画块被执行并丢弃.但是self在NSNotification观察器块中的引用可能会导致保留周期,因为它只是由系统永久保留,直到您取消注册该通知,同时保留观察者.
| 归档时间: |
|
| 查看次数: |
889 次 |
| 最近记录: |