【问题标题】:unwanted constraint personal hotspot start bar不需要的约束个人热点开始栏
【发布时间】:2018-07-17 12:47:22
【问题描述】:

在设备中启动我的应用程序后, 如果显示个人热点, 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];
}

但是有没有办法消除热点/通话限制?

当热点/通话处于活动状态时,我希望 view.frame.origin 也为 0,0。

【问题讨论】:

    标签: ios objective-c uiviewcontroller ios-autolayout


    【解决方案1】:

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

    在通话期间,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 中的以下代码尝试打破约束,但这是不推荐,因为我们正在打破由UIKit 设置的约束这可能会导致问题。通过迭代应用程序的窗口数组,我们基本上打破了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];
            }
        }
    }
    

    斯威夫特

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

    【讨论】:

    • 谢谢,但我已经用“修复”解决了这个问题。我想要“干净”的方式。意思是,尝试摆脱不需要的约束(我的应用程序不使用自动布局),也许这会使 uiview 始终为 0,0
    • 你知道如何摆脱束缚吗?我尝试了一些没有成功的事情。我看不出有什么理由让默认的 uiview 需要更改其来源,因为有通话,因为没有通话时,状态栏为 20,uiview 为 0,0
    • 可能是因为它是在通话时限制视图降低的方式。打破约束(如您的警告消息中所示)似乎是 Apple 的一个错误。请检查编辑的答案。
    • 我稍后会检查并更新。但是,你涵盖了一切。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    • 2021-02-10
    相关资源
    最近更新 更多