无用约束个人热点启动栏

unwanted constraint personal hotspot start bar

在设备中启动我的应用程序后, 如果显示个人热点, xcode 在控制台中写入:

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(

"<NSLayoutConstraint:0x146dd7cf0 V:|-(20)-[UIInputSetContainerView:0x146dd43e0]   (Names: '|':UITextEffectsWindow:0x146dd2ee0 )>",
"<NSLayoutConstraint:0x146dbd950 'UIInputWindowController-top' V:|-(0)-[UIInputSetContainerView:0x146dd43e0]   (Names: '|':UITextEffectsWindow:0x146dd2ee0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x146dd7cf0 V:|-(20)-[UIInputSetContainerView:0x146dd43e0]   (Names: '|':UITextEffectsWindow:0x146dd2ee0 )>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

我的应用程序使用自动布局或约束。 (ios 9.3.5, ios 11)

问题还在于正常状态下的rootViewController是0,0原点, 但是当有电话时它是0,20我不能把它改成0,0.

编辑: 我设法通过添加

来解决这个问题
-(void)viewDidLayoutSubviews
{
    self.view.frame = [[UIScreen mainScreen] bounds];
}

但是 有没有办法删除 hotspot/incall 约束?

我希望 view.frame.origin 在 hotspot/incall 激活时也为 0,0。

你可以试试听UIApplicationDelegate的这个方法(willChangeStatusBarFrame)来改变状态栏的框架并相应地修改你的视图位置:

在 phone 调用期间,iPhone SE 中新的、更改的状态栏框架如下所示:

CGRect  (origin = (x = 0, y = 0), size = (width = 320, height = 40))    

这是状态栏正常时的状态:

CGRect  (origin = (x = 0, y = 0), size = (width = 320, height = 20))    

因此,当设备处于通话状态时,您可以只偏移视图的 y+20 点或设置为 0,如您最初想要的那样并修复. 这是 right/clean 更改框架以响应状态栏框架更改的方法。这比在 viewDidLayoutSubviews.

中设置视图的框架更好

但是,您可以根据需要在 willChangeStatusBarFrame 中使用以下代码尝试打破约束,但不推荐,因为我们正在打破约束这是由 UIKit 设置的,这可能会导致问题。我们基本上是通过遍历应用程序的 windows:

数组来打破 UITextEffectsWindow 的约束

Objective-C

- (void)application:(UIApplication *)application willChangeStatusBarFrame:(CGRect)newStatusBarFrame {
    for(UIWindow *window in [[UIApplication sharedApplication] windows]) {
        if([window.class.description containsString:@"UITextEffectsWindow"]) {
            [window removeConstraints:window.constraints];
        }
    }
}

Swift

func application(_ application: UIApplication, willChangeStatusBarFrame newStatusBarFrame: CGRect) {
    for window in UIApplication.shared.windows {
        if window.self.description.contains("UITextEffectsWindow") {
                window.removeConstraints(window.constraints)
        }
    }
}