我有一個可以包含兩個子視圖控制器的自定義視圖控制器。當設備處於縱向方向時,其中一個控制器的視圖變得可見。當設備處於橫向方向時,其他控制器的視圖變爲可見。然而,當橫向取向視圖可見時,狀態欄會縮回以爲特定視圖留出更多空間。設備重新轉換爲縱向模式後,狀態欄不顯示。這是自定義視圖控制器顯示在UINavigationController
內。iOS隱藏和取消隱藏狀態欄沒有正確移動子視圖
我的問題是,當狀態欄的可見性變化時,我的子視圖不能正確調整。有最終被一個大的間隙和/或重疊,當開啓設備在不同的取向,如下圖所示:
正如你可以看到,它最初是細(縱向),但是當該裝置被關,狀態欄是白色的空白處。當設備轉回肖像時,UINavigationController
的導航欄會顯示並與狀態欄重疊,導航欄與其下方視圖之間會出現間隙。如果從一個風景方向到另一個風景方向旋轉180度非常快,則間隙消失並且看起來很好。
下面的方法屬於自定義視圖控制器和willAnimateRotationToInterfaceOrientation:duration:
被稱爲(顯然處理旋轉事件)和viewDidAppear:
(處理當視圖從以前視圖控制器在被推入導航棧)。
- (void)cueAnimationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation fromViewDidAppear:(BOOL) fromViewDidAppear
{
// Fading animation during orientation flip.
// Make sure its not already animating before trying.
BOOL barHidden = [UIApplication sharedApplication].statusBarHidden;
if (!isAnimating) {
BOOL alreadyGoodGrid = (UIInterfaceOrientationIsLandscape(interfaceOrientation) && curView == self.gridViewController.view);
BOOL alreadyGoodTable = (UIInterfaceOrientationIsPortrait(interfaceOrientation) && curView == self.tableViewController.view);
if ((alreadyGoodGrid && barHidden) ||
(alreadyGoodTable && !barHidden)) {
// If views are the way they should be for this orientation. Don't do
// anything.
return;
}
isAnimating = YES;
UIView *nextView;
// Get starting orientation. This will determine what view goes on top
if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
nextView = self.gridViewController.view;
else
nextView = self.tableViewController.view;
if (nextView == self.tableViewController.view)
{
if (!alreadyGoodTable)
{
self.tableViewController.view.alpha = 0.0;
[self.view bringSubviewToFront:self.tableViewController.view];
}
// Unhide the bar for the table view
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
}
else // gridViewController
{
if (!alreadyGoodGrid)
{
self.gridViewController.view.alpha = 0.0;
[self.view bringSubviewToFront:self.gridViewController.view];
}
// Hide the bar for the grid view
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
}
[UIView animateWithDuration:0.4
delay: 0.0
options: UIViewAnimationOptionAllowUserInteraction
animations:^{
if (nextView == self.tableViewController.view) {
self.tableViewController.view.alpha = 1.0;
}
else {
self.gridViewController.view.alpha = 1.0;
}
}
completion:^(BOOL finished) {
if (nextView == self.tableViewController.view) {
curView = self.tableViewController.view;
}
else {
curView = self.gridViewController.view;
}
isAnimating = NO;
}];
}
}
非常感謝任何人,可以花時間看看這個。
感謝您的幫助。對你有好處。我確實得到了另一個解決方案,似乎很好,我只是作爲答案發布。 – 2013-03-04 03:40:57
很高興你找到了一些東西 - 也許它會幫助我! – 2013-03-04 16:12:46