Is there a way to automatically detect when a UIView changes it's apparent scale on the screen, because one of its parents changed scale? Note that I'm not asking how to detect if the UIView's own scale property changes, but that of one of its parents?
Asked
Active
Viewed 93 times
1 Answers
1
Yes. There are several ways to do that (without even searching, I knew we could do that by KVO, RxSwift, or ReactiveCocoa.). So, yeah, use KVO if you're not into reactive programming. But I am also thinking you could just use NotificationCenter, sent by your parent view class. I forgot the other way that I was thinking, I was about to type it here but it's gone, sad.
Anyways, example:
[self.view addObserver:self forKeyPath:@"frame" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"bounds" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"transform" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"position" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"zPosition" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"anchorPoint" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"anchorPointZ" options:0 context:NULL];
[self.view.layer addObserver:self forKeyPath:@"frame" options:0 context:NULL];
The code block came from this answer: https://stackoverflow.com/a/19687115/3231194
I hope this helps!

Glenn Posadas
- 12,555
- 6
- 54
- 95