原因是当录音的时候,状态栏高度由20变成了40,导致controller整体下移了20
小知识,controller的self.view 即controller显示的大小,通过改变self.view大小 就能控制controller的大小
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
CGRect frame = self.view.frame;
frame.size.height -= 20;
// frame.origin.y += 20;
self.view.frame = frame;
self.view.clipsToBounds = YES;
}
- 监听状态栏变化的通知
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeFrame) name:UIApplicationWillChangeStatusBarFrameNotification object:nil];
- 当状态栏改变时更新controller的self.view大小
self.oldHeight = [UIScreen mainScreen].bounds.size.height;
- (void)changeFrame{
CGRect frame = self.view.frame;
self.view.clipsToBounds = YES;
CGRect statusBarRect = [[UIApplication sharedApplication] statusBarFrame];
if (statusBarRect.size.height == 40) {
frame.size.height = self.oldHeight - 20 - frame.origin.y;
}
if (statusBarRect.size.height == 20){
frame.origin.y = 0;
frame.size.height = self.oldHeight;
}
self.view.frame = frame;
}
项目地址
你可能需要这个