gpt4 book ai didi

iphone - 动态改变 UIView Frame

转载 作者:行者123 更新时间:2023-11-29 13:19:24 25 4
gpt4 key购买 nike

我有这样一个场景: View B 框架取决于 View A 框架。我正在玩 viewA 框架。但是 View b 框架不会改变,因为框架不是对象。那么解决方法是什么,如果我需要将 View B frame wrt 更改为 View A Frame 即当我更改 ViewA 框架时, View B 框架会发生变化

最佳答案

一个解决方案是 add KVO对于 View A因为它会notify什么时候frame changed并根据 changeframeview A , change frameview B

[A addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld context:NULL];  //added KVO for View A

方法是:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if([keyPath isEqualToString:@"frame"]) {
//change frame of View B according to View A
}
}

编辑:Remove observer什么时候不needed

[A removeObserver:self forKeyPath:@"frame"];

关于iphone - 动态改变 UIView Frame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744564/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com