所以,現在我只是使用KVO。我遵循了一些建議here。
在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.
}
}
}
我想這在視圖的邊界,但在框架上開了很多更經常比國際志願者組織。