不受欢迎的约束个人热点开始吧

时间:2018-02-07 09:32:09

标签: ios objective-c uiviewcontroller ios-autolayout

在设备中启动应用后, 如果个人热点正在显示, 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 origin, 但是当有呼叫它是0,20时我无法将其改为0,0。

编辑: 我设法通过添加

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

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

我希望当hotspot / incall处于活动状态时,view.frame.origin也将为0,0。

1 个答案:

答案 0 :(得分:1)

您可以尝试使用willChangeStatusBarFrame的此方法(UIApplicationDelegate)来更改状态栏的框架并相应地修改您的观看位置:

在通话过程中, 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,就像您最初想要的那样并且已修复。这是更改框架以响应状态栏框架更改的正确方法。这比在viewDidLayoutSubviews中设置视图的框架要好。

但是,您可以尝试使用willChangeStatusBarFrame中的以下代码来破坏约束,但它是 NOT RECOMMENDED ,因为我们打破了{设置的约束' {1}}这可能会导致问题。我们基本上通过迭代应用程序的窗口数组来打破UIKit的约束:

<强>目标C

UITextEffectsWindow

<强>夫特

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