调整通话状态栏的大小?

发布于 2024-07-26 22:38:35 字数 143 浏览 4 评论 0原文

如何根据笔尖上的通话状态栏调整视图大小?

我认为它只是设置调整大小属性,但它们没有为根 UIView 启用。

(我认为我的主要问题是我不知道这一切叫什么;除了谈论模拟器菜单命令之外,我在任何文档中都找不到对通话中状态栏的任何引用。)

How can I make my view resize in response to the in-call status bar from my nib?

I figured it would just be setting the resize properties, but they're not enabled for the root UIView.

(I think my main problem here is I don't know what any of this is called; I can't find any reference to the in-call status bar in any of the documentation except where it talks about the simulator menu command.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

幻梦 2024-08-02 22:38:36

只要状态栏发生变化,iOS 就会调用 viewController 的 viewWillLayoutSubviews 方法。 您可以覆盖它并根据新的边界调整您的子视图。

- (void)viewWillLayoutSubviews {
    // Your adjustments accd to 
    // viewController.bounds

    [super viewWillLayoutSubviews];
}

iOS will invoke your viewController's viewWillLayoutSubviews method whenever there is a change in status bar. You can override that and adjust your subviews according to the new bounds.

- (void)viewWillLayoutSubviews {
    // Your adjustments accd to 
    // viewController.bounds

    [super viewWillLayoutSubviews];
}
黑色毁心梦 2024-08-02 22:38:36

您正在寻找 -[UIApplication statusBarFrame],并且在 UIApplicationDelegate 中,您应该实现此委托方法,以便在状态栏的框架发生更改时收到通知:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame  

You're looking for -[UIApplication statusBarFrame] and, in your UIApplicationDelegate, you should implement this delegate method to be notified of when the status bar's frame changes:

- (void)application:(UIApplication *)application didChangeStatusBarFrame:(CGRect)oldStatusBarFrame  
失而复得 2024-08-02 22:38:36

如果您没有设置根视图控制器,视图可能不会随着状态栏大小的变化自动调整大小。 我最初在我的应用程序委托中拥有此功能,并且我的应用程序在所有方面都工作正常,只是在通话期间它无法正确调整大小。

[self.window addSubview:rootController.view];

我将上面的行更改为这一行,现在我的应用程序在通话期间自动调整大小。

[self.window setRootViewController:rootController];

在日志中看到此内容并调查原因后,我发现了此修复程序。

Application windows are expected to have a root view controller at the end of application launch

A view may not resize automatically with status bar size changes if you do not have a root view controller set. I originally had this in my app delegate, and my app worked properly in all regards except that it would not resize correctly during phone calls.

[self.window addSubview:rootController.view];

I changed the above line to this, and now my app resizes automatically during calls.

[self.window setRootViewController:rootController];

I discovered this fix after seeing this in the log and investigating the cause.

Application windows are expected to have a root view controller at the end of application launch
阳光下的泡沫是彩色的 2024-08-02 22:38:36

当我的应用程序在后台运行并且我按 command + T 时,这对我来说非常有效。在我的场景中,根控制器是我的选项卡栏控制器,我正在每个选项卡内重新调整我的导航控制器。

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame{
[UIView animateWithDuration:0.35 animations:^{
    CGRect windowFrame = ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame;
    if (newStatusBarFrame.size.height > 20) {
        windowFrame.origin.y = newStatusBarFrame.size.height - 20 ;// old status bar frame is 20
    }
    else{
        windowFrame.origin.y = 0.0;
    }
    ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame = windowFrame;
}];

}

this works for me perfectly when my application is running in background and I press command + T. In my scenario , the root controller is my tab bar controller and I am readjusting my nav controller inside each tab.

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame{
[UIView animateWithDuration:0.35 animations:^{
    CGRect windowFrame = ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame;
    if (newStatusBarFrame.size.height > 20) {
        windowFrame.origin.y = newStatusBarFrame.size.height - 20 ;// old status bar frame is 20
    }
    else{
        windowFrame.origin.y = 0.0;
    }
    ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame = windowFrame;
}];

}

我只土不豪 2024-08-02 22:38:36

当您说“根 UIView 未启用调整大小属性”时,您是什么意思?

通话中的状态栏没有任何特殊的名称,我认为它周围没有任何 API 或通知。 相反,您的视图应该简单地设置为正确自动调整大小。

尝试在 Xcode 中创建一个新的基于导航的应用程序,并研究 RootViewController.xib 中表格视图的自动调整大小设置。 希望您会看到 Apple 的设置与您在项目中设置的内容之间存在差异。

What do you mean when you say that 'the resize properties aren't enabled for the root UIView'?

The in-call status bar doesn't have any particular special designation, and I don't think there are any APIs or notifications around it. Instead, your views should simply be set up to autoresize correctly.

Try creating a new navigation-based app in Xcode and study the autoresize settings on the table view in RootViewController.xib. Hopefully you'll see a delta between what Apple's set and what you've set in your project.

做个ˇ局外人 2024-08-02 22:38:36

对于像 UITableView 这样的视图,您通常需要更改表格单元格高度,除了实现 application:didChangeStatusBarFrame: 之外,没有其他方法可以做到这一点。 但这没什么大不了的,如果需要,您可以将行高设置为非整数值。

For views like UITableView you'll typically need to change the table cell height, and there's no other way to do it except to implement application:didChangeStatusBarFrame:. But it's no biggie, and you can set the row height to non-integer values if you need to.

浅浅 2024-08-02 22:38:36

状态栏更改框架的通知是

UIApplicationWillChangeStatusBarFrameNotification

注册为观察者:

[[NSNotificationCenter defaultCenter] addObserver:self
选择器:@selector(statusBarFrameWillChange:)名称:UIApplicationWillChangeStatusBarFrameNotification对象:nil];

然后响应处理程序中的更改:

- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// 响应变化
即使自动

布局设置正确,您也可能需要响应更改。 例如,根据屏幕中给定空间计算单元格高度的表格视图可能需要在状态栏更改后reloadData

文档

The notification for status bar changing frame is

UIApplicationWillChangeStatusBarFrameNotification

Register as an observer:

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(statusBarFrameWillChange:)name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

Then respond to change in your handler:

- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// respond to changes
}

Even with autolayout setup correctly, you may need to respond to changes. For example, a table view that calculates its cell height based on the given space in the screen would may need to reloadData after the status bar changed.

Documentation

翻了热茶 2024-08-02 22:38:36

我也遇到了同样的问题。 我所做的就是这个。

  1. 在 IB 中打开 xib 文件
  2. 默认情况下,所有界面元素都附加为与顶部一起移动,并显示在“大小检查器”的“自动调整大小”属性中。 因此,对于屏幕底部的 UI 元素,请删除顶部的链接,而是从底部创建链接。 保留所有其他内容不变。
  3. 问题解决了!!!

我希望我说清楚了。

I was having the same problem. What I did was this.

  1. Open the xib file in IB
  2. All interface elements are by default attached to move along with with top and shown in the 'Autosizing' property in the 'Size Inspector'. So, for the UI elements at the bottom of the screen, remove the link from top and instead make the link from bottom. Leave all the others as is.
  3. Problem Solved!!!

I hope I was clear.

逆流 2024-08-02 22:38:36

如果您以编程方式设置视图框架,则必须手动更新视图。

 -(void) viewDidAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(statusBarFrameWillChange:)name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

}

- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// respond to changes
NSLog(@"STATUS BAR UPDATED");
NSDictionary *statusBarDetail = [notification userInfo];
NSValue *animationCurve = statusBarDetail[UIApplicationStatusBarFrameUserInfoKey];
CGRect statusBarFrameBeginRect = [animationCurve CGRectValue];
int statusBarHeight = (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation])) ? statusBarFrameBeginRect.size.height : statusBarFrameBeginRect.size.width;

NSLog(@"status bar height  %d", statusBarHeight);
}

-(void) viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationBackgroundRefreshStatusDidChangeNotification object:nil];
}

这将为您提供状态栏的新高度,并使用它可以相应地更新框架。

You will have to update the views manually if you are setting your view frames programatically

 -(void) viewDidAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(statusBarFrameWillChange:)name:UIApplicationWillChangeStatusBarFrameNotification object:nil];

}

- (void)statusBarFrameWillChange:(NSNotification*)notification
{
// respond to changes
NSLog(@"STATUS BAR UPDATED");
NSDictionary *statusBarDetail = [notification userInfo];
NSValue *animationCurve = statusBarDetail[UIApplicationStatusBarFrameUserInfoKey];
CGRect statusBarFrameBeginRect = [animationCurve CGRectValue];
int statusBarHeight = (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication]statusBarOrientation])) ? statusBarFrameBeginRect.size.height : statusBarFrameBeginRect.size.width;

NSLog(@"status bar height  %d", statusBarHeight);
}

-(void) viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationBackgroundRefreshStatusDidChangeNotification object:nil];
}

This gives you the new height of the status bar and using this you can update your frames accordingly.

简单 2024-08-02 22:38:36

解决方案是确保您已设置窗口键:

[window makeKeyAndVisible];

如果您不这样做,则子视图不会自动调整大小,但据我所知,没有其他症状。

The solution is to ensure you have made your window key:

[window makeKeyAndVisible];

If you don't do that the subview does not get resized automatically, but there are no other symptoms as far as I know.

我为君王 2024-08-02 22:38:36

之前发布的解决方案都不适合我。 对我有用的是我没有为我的观点正确设置约束。 在我的情况下,我的视图中有两个不同的容器视图。

故事板中场景的视图。

底部(在列表中)容器视图是一个 UITableView,它没有正确滚动到表格底部。 原因是通话中状态栏的偏移导致 UITableView 的原点(左上角)发生变化,但大小仍保持不变。 这意味着桌子的底部超出了屏幕!

解决方案是正确设置自动调整大小高度约束。 在下面的屏幕截图中,它是“自动调整大小”框中间的垂直箭头。

在此处输入图像描述

None of the solutions posted before worked for me. What did work for me was that I didn't have my constraints set up properly for my views. In my situation, I had two different container views within my view.

View of scene in storyboard.

The bottom (in the list) container view was a UITableView, which was not scrolling correctly to the bottom of the table. The reason was that the offset of the in-call status bar was causing the origin (top-left corner) of the UITableView to change, but the size would remain this same. This meant that the bottom of the table was off screen!

The solution was to correctly set the Autoresizing height constraint properly. In the screenshot below, it is the vertical arrows in the middle of the Autoresizing box.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文