だから、今のところ私はKVOを使っています。ここでいくつかのアドバイスに従いました。
でviewDidLoad
:
[self.view addObserver:self
forKeyPath:NSStringFromSelector(@selector(frame))
options:(NSKeyValueObservingOptionOld|NSKeyValueObservingOptionNew)
context:nil];
それで:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([object isKindOfClass:[UIScrollView class]] && [keyPath isEqualToString:NSStringFromSelector(@selector(frame))]) {
CGRect newFrame = [change[@"new"] CGRectValue];
CGRect oldFrame = [change[@"old"] CGRectValue];
if ((newFrame.size.width == oldFrame.size.width) || (newFrame.size.height == oldFrame.size.height)) {
// If one dimension remained constant, we assume this is a displayMode change instead of a rotation
// Make whatever changes are required here, with access to new and old frame sizes.
}
}
}
ビューの境界でこれを試しましたが、フレームの KVO よりも頻繁に発生しました。