Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
针对特定情况优化iOS应用程序_Ios_Iphone_Objective C - Fatal编程技术网

针对特定情况优化iOS应用程序

针对特定情况优化iOS应用程序,ios,iphone,objective-c,Ios,Iphone,Objective C,当用户打开internet共享时,顶部的黑色条会变成蓝色并变宽,这会导致用户界面稍微下降,并导致一些问题,由于该界面现在看起来很奇怪,因为项目被向下推,并且可能在底部被切断。有没有办法处理这种情况?如果是的话,有没有教程可以帮助你呢?我一直在寻找,但还没有找到任何东西 您可以处理UIApplicationWillChangeStatusBarFrameNotification和UIApplicationIDChangeStatusBarOrientationNotification通知,这些通知

当用户打开internet共享时,顶部的黑色条会变成蓝色并变宽,这会导致用户界面稍微下降,并导致一些问题,由于该界面现在看起来很奇怪,因为项目被向下推,并且可能在底部被切断。有没有办法处理这种情况?如果是的话,有没有教程可以帮助你呢?我一直在寻找,但还没有找到任何东西

您可以处理
UIApplicationWillChangeStatusBarFrameNotification
UIApplicationIDChangeStatusBarOrientationNotification
通知,这些通知将告诉您状态栏的新大小。如果需要,您可以使用此选项调整UI。避免硬编码任何内容(例如40pt),而是从通知中获取新的状态栏框架

如果你只需要高度,你可以很容易地把它拔出来。如果您需要对状态栏框架执行更复杂的操作,则必须将其从屏幕坐标转换为您自己视图的坐标系(例如,如果您有一个全屏布局视图控制器,并且需要在其下方进行布局):


在iOS 7中,坐标的转换尤其重要,因为默认情况下,所有视图控制器都有全屏布局。

那么,我是否必须将坐标添加到每个视图中,以更改其中的项目?@mikeweller的回答很有帮助,但苹果对这个问题的建议是自动布局。避免自动布局的尝试会遇到越来越多的问题,因为越来越多的iOS依赖于您的使用。这一趋势只是在增加。
- (void)statusBarFrameWillChangeNotification:(NSNotification *)notification
{
    NSValue *rectValue = notification.userInfo[UIApplicationStatusBarFrameUserInfoKey];

    CGRect statusBarFrame = [rectValue CGRectValue];

    // if you just need the height, you can stop here

    // otherwise convert the frame to our view's coordinate system
    UIWindow *targetWindow = self.view.window;
    // fromWindow:nil here converts from screen coordinates to the window
    CGRect statusBarFrameWindowCoords = [targetWindow convertRect:statusBarFrame
                                                       fromWindow:nil];
    CGRect frameRelativeToOurView = [self.view convertRect:statusBarFrameWindowCoords
                                                  fromView:targetWindow];

    // ...
}