Iphone 视图高度在旋转后更改
“我的网络视图”显示包含视频的网页。此Web视图包含导航栏和状态栏 问题是,在以横向模式观看视频并返回webview后,视图高度会发生变化。当时没有任何webview方法被调用 它在纵向观看模式下工作良好 以下是一些视图的屏幕截图:Iphone 视图高度在旋转后更改,iphone,objective-c,Iphone,Objective C,“我的网络视图”显示包含视频的网页。此Web视图包含导航栏和状态栏 问题是,在以横向模式观看视频并返回webview后,视图高度会发生变化。当时没有任何webview方法被调用 它在纵向观看模式下工作良好 以下是一些视图的屏幕截图: 观看视频前/观看纵向旋转视频后 在观看横向旋转的视频后 为什么会发生这种情况?在观看视频后尝试添加这一行 [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UISta
观看视频前/观看纵向旋转视频后
在观看横向旋转的视频后
为什么会发生这种情况?在观看视频后尝试添加这一行
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
更新:
- (void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"MPAVControllerPlaybackStateChangedNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(update:) name:@"MPMoviePlaybackStateInterrupted" object:nil];
}
更新方法如下
#pragma mark -
#pragma mark NSNotification Action
- (void)update:(NSNotification *)n {
NSLog(@">>>>>>>>>>>>>>>>>> Str Key ===>>%@",[NSNotificationCenter defaultCenter]);
NSLog(@"\n\n\n\n\n>>>>>>>>>>> Updateing >> %@ >>>>>>>>\n\n",[n description]);
if ([[[n userInfo]objectForKey:@"MPAVControllerNewStateParameter"] intValue] == 0) {
NSLog(@">>>>>> 1111111111111111111111111111111111111");
}
/*
>>>>>>>>>>> Updateing >> NSConcreteNotification 0x9c85740 {name = MPAVControllerPlaybackStateChangedNotification; object = <MPAVController: 0x6770010>; userInfo = {
MPAVControllerNewStateParameter = 1;
MPAVControllerOldStateParameter = 2;
}}>>>>>>>>
*/
if ([[[n userInfo]objectForKey:@"MPAVControllerNewStateParameter"] intValue] == 1 && [[[n userInfo]objectForKey:@"MPAVControllerOldStateParameter"] intValue] == 2 ) {
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
//[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
}
}
#pragma标记-
#pragma标记通知操作
-(无效)更新:(NSNotification*)n{
NSLog(@“>>>>>>>>>>>>>>>>>>Str Key===>>%@,[NSNotificationCenter defaultCenter]);
NSLog(@“\n\n\n\n>>>>>>>>>>>%@>>>>>>>>>>\n\n”,[n说明];
如果([[[n userInfo]objectForKey:@“MPAVControllerNewStateParameter”]intValue]==0){
NSLog(@“>>>>>>1111111111111111111111111111”);
}
/*
>>>>>>>>>>>更新>>NSConcreteNotification 0x9c85740{name=MPAVControllerPlaybackStateChangedNotification;对象=;用户信息={
MPAVControllerNewStateParameter=1;
MPAVControllerOldStateParameter=2;
}}>>>>>>>>
*/
如果([[[n userInfo]objectForKey:@“MPAVControllerNewStateParameter”]intValue]==1&[[n userInfo]objectForKey:@“MPAVControllerOldStateParameter”]intValue]==2){
[[UIApplication sharedApplication]设置StatusBarHidden:NO with animation:UIStatusBaranimationne];
//[[UIDevice currentDevice]设置方向:UIInterfaceOrientation纵向];
}
}
我解决这个问题的方法非常简单,基本上是问题的核心:当你旋转视图,导航控制器重新计算它的新位置时,它认为它应该在窗口的顶部,因为状态栏是隐藏的。之后显示状态栏和导航栏时,它们是重叠的
解决这个问题的方法非常简单,只需保留一个BOOL来记住覆盖是显示还是隐藏,并在ViewController中实现willRotateToInterfaceOrientation和WillAnimateRotationInterfaceOrientation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (!isOverlayShowing)
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (!isOverlayShowing)
{
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
通过在这两种方法中快速显示和隐藏状态栏,状态栏将在导航栏重新计算其位置时显示。我不知道这是否是解决此问题的最佳实现,但到目前为止,此方法有效,不会在屏幕上产生任何闪烁,并且非常平滑。但是在哪里设置Bool变量。将其放在您的ViewController中。m它应该可以正常工作。好的,我认为您使用HTML5页面来解决此问题??看看试试我的更新代码…@rohanpanchal嘿,看看代码,试试看,在看了我代码中的视频后,在potrait中使用一些额外的功能,比如设置方向等等。。。。这只是额外的信息。。希望这对你有帮助..不,这不是错误,但在iOS 4.3之后它不会响应UIDevice,我认为是从那个版本开始的,但只是评论一下,然后再试一下。。。它不是imp.@rohanpanchal我添加了需要在另一个条件中添加的行dude现在我添加了这行,请看dude,然后尝试…而不是设置statusbar隐藏在条件中,我为导航栏设置了框架,如:self.navigationController.navigationBar.Frame=CGRectMake(0,20,320,44);谢谢你的回复!!正确设置自动调整大小的遮罩,因为我已经尝试过了&对我来说效果很好。