ios - 无用约束个人热点启动栏

标签 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原点, 但是当有电话时,它是 0,20,我无法将其更改为 0,0。

编辑: 我设法通过添加来解决这个问题

-(void)viewDidLayoutSubviews
{
    self.view.frame = [[UIScreen mainScreen] bounds];
}

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

我希望 view.frame.origin 在 hotspot/incall 处于事件状态时也为 0,0。

最佳答案

您可以尝试监听 UIApplicationDelegate 的此方法 (willChangeStatusBarFrame) 以更改状态栏的框架并相应地修改您的 View 位置:

在通话期间,iPhone SE 中新的、更改的状态栏框架如下:

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

这是状态栏处于正常状态时:

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

因此,当设备处于通话状态时,您只需偏移 View 的 y+20 点或设置为 0正如您最初想要的那样并已修复。这是更改框架以响应状态栏框架更改的正确/干净的方法。这比在 viewDidLayoutSubviews 中设置 View 的框架要好。


但是,您可以根据需要在 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];
        }
    }
}

swift

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

关于ios - 无用约束个人热点启动栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48660242/

相关文章:

java - 从 Java 学习 iPhone 编程的最佳方法是什么?

iOS如何知道坐标是否正确

ios - 对 Modal ViewController 被解雇使用react

ios - UIImage 在 ObjectiveC 中编码为 NSData,然后在 Swift 中解码

ios - AudioQueueStart 发布消息以终止 mediaserverd

objective-c - 代码 "Could not launch Game Name, no such file or directory..."

ios - 相当于 UIViewController 的 ContentInset?

iphone - iOS View - 如何去除过多的阴影?

ios - 有没有办法在消息和我的 iOS 应用程序之间进行通信?

ios - 几天后PFUser currentUser返回null