在写项目的时候有时候我们会遇到这样的问题的:
ScrollView作为界面盛放其他的View的Scroll回向下偏移64哥像素:
解决这类问题的方案:
1.在ios 7以前在ViewController的init 里面添加:
self.automaticallyAdjustsScrollViewInsets = NO;
2.在ios8之后使用观察者模式:
[_scrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{
if ([keyPath isEqualToString:@"contentInset"]){
double version = [[UIDevice currentDevice].systemVersion doubleValue];//判定系统版本。
if(version>=8.0f){
_scrollView.frame =CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64.0f - 50.0f);
}
}else{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}