我添加了使用安全区域指南的选项,但当我查看应用程序时,它似乎尊重安全区域,但有一些我无法摆脱的空白。我不知道是什么原因造成的,也不知道如何改变白色的颜色。
我已将背景颜色设置为您在下面看到的颜色。
view.backgroundColor = UIColor(red:0.227, green:0.251, blue:0.294, alpha:1)
我还设置了白色状态栏样式
UIApplication.shared.statusBarStyle = UIStatusBarStyle.lightContent
我的主要故事板
在iphone x中设置安全区域后。当键盘打开时,安全区域(键盘上方的白色区域)位于键盘上方,那么如何操作键盘?
键盘上方的白色区域。
处理键盘代码:-
func keyboardWillChangeFrameWithNotification(_ notification: Notification, showsKeyboard: Bool) {
        let userInfo = notification.userInfo!
        let animationDuration: TimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
        let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
        // keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
        let keyBoardRect = self.view.convert(keyboardScreenEndFrame, from:nil)
        UIView.animate(withDuration: animationDuration, delay: 0, options: .beginFromCurrentState, animations: {
            // Keyboard is going to appear. move composebar up
            if showsKeyboard {
                self.constraintBottomAttachmentView.constant =  keyBoardRect.size.height
            } else { // Keyboard is going to disappear. Move composebar down.
                self.constraintBottomAttachmentView.constant = 0
            }
            self.view.layoutIfNeeded()
            }, …我正在inputAccessoryView使用UIViewController. 一切正常,直到我改变UIWindows rootViewController。之后,safeAreaInsets肖像被报告为风景,反之亦然。
rootViewController仅当从具有键盘输入的位置进行更改时才会发生这种情况。
以下是重现该问题的示例项目:https ://github.com/jcavar/ChangeRootSafeArea
我想这是某种魔法UITextEffectsWindow造成的。我尝试在更改之前完全删除它rootViewController,但随后输入附件视图不再出现。
对此有什么想法吗?
我遇到的问题是,当标签应该锚定到安全区域布局指南时,标签却锚定到屏幕的底部边缘。这将使标签位于 iPhone 系列之上。
这是代码...
class CustomTableViewController: UITableViewController {
   override func viewDidLoad() {
       super.viewDidLoad()
       tableView.tableFooterView = UIView(frame: .zero)
       tableView.backgroundView = CustomBackgroundView()
   } 
}
。
class CustomBackgroundView: UIView {
   override init(frame: CGRect) {
       super.init(frame: frame)
       setupSubviews()
   }
   required init?(coder aDecoder: NSCoder) {
       fatalError("init(coder:) has not been implemented")
   }
   private func setupSubviews() {
       let label = UILabel()
       label.text = "Hello, World!"
       label.textAlignment = .center
       label.translatesAutoresizingMaskIntoConstraints = false
       addSubview(label)
       label.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
       label.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor).isActive = true
   } 
}
在与这篇文章相同的主题中:
iOS 13 - UIPopoverPresentationController sourceview 内容在箭头中可见
我有一个从故事板实例化的 UITableViewController。我在 UIPopoverViewController 中展示它。
根据方向,我要么缺少一侧,要么缺少顶部,_UITableViewHeaderFooterViewBackground 的内容“通过”箭头滚动。
怎么了:
这些是当它在顶部时,但如果它出现在侧面,那么整个侧面
编辑:我正在使用安全区域指南:
正如我之前所说,我从对象库中拖出一个全新的 UITVC,然后将原型单元更改为我的应用程序的要求。
我对任何安全区域切换或设置进行了零更改。
我不会更改代码中的任何安全区域插入或调整。
所以,谢谢@Alex,但这不是问题,或者如果是,我不知道该怎么办。
编辑2:
今天下午,我确保我的班级中的代码为零,可以执行任何格式、颜色、插入或任何与更改默认表格单元格的任何形式有关的工作。
然后我在 IB 中完全删除了我的 UITVC 并创建了一个新的,创建新的原型单元,除了在单元中放置一个 UIImageView 之外没有样式。
我确保 UITVC、tableviewcell 和内容视图都在 IB 中勾选了“安全区域”和“安全边距”。
重建应用程序并运行。
完全相同的。
我仍然有内容和背景越过箭头,如果我然后在表格周围添加边框,则呈现侧被“切断”。
编辑 3:
我知道问题是什么!!!
这是 _UITableViewHeaderFooterViewBackground 不能很好地与 AutoLayout 配合使用!!
我不确定如何解决它,但这就是问题所在。
编辑 4 / 更新:
今天我构建了以下应用程序,即使没有节标题,该错误仍然存在!
在 IB 中,创建一个带有两个按钮的 UIVC,一个左上角,另一个右上角。
从资产目录中拖出一个 UITVC 并将其放在原始 VC 的一侧,然后从资产库中拖出一个 UIVC 并将其放在另一侧。
将 UITableView 从资产库拖到“新” UIViewController 上,只需将其顶部和底部设置为引导安全区域布局,将左右设置为安全边距,0 常量(您可以保留默认值 20 - 没有区别)。
现在,将这些按钮连接到原始 UIVC,以便按下每个按钮会实例化一个或其他两个控制器,并在弹出窗口中显示它们。
请注意,在任何 UIViewController 上都没有格式化、没有样式、没有更改任何默认的 IB 设置。
这是“中心” …
uitableview uipopovercontroller swift safearealayoutguide ios13
safeAreaInset(edge:alignment:spacing:content:):
\n\nThe modified view is inset by the height of content, from edge, with its safe area increased by the same amount.
\n
看来 SwiftUIsafeAreaInset没有导入 UIKit 的安全区域:
        ZStack {\n            Color.black\n            UIKitView()\n        }\n        .ignoresSafeArea(edges: .top)\n        .safeAreaInset(edge: .top) {\n            Text("TOP")\n                .frame(minHeight: 200)\n                .background(Color.cyan.opacity(0.5))\n        }\n在此示例中,视图black和 的UIKitView布局相同 - 它们忽略safeAreaInset:top和状态栏。
问题是:如何了解UIKitView游戏中的安全区域?
考虑以下:
\nstruct UIKitView: UIViewControllerRepresentable {\n    func makeUIViewController(context: Context) -> some UIViewController { ViewController() }\n …*看上面的图片链接,支持iOS9到iOS11
\n\n以下是工作代码解决方案:
\n\nimport UIKit\nimport WebKit\n\nclass ViewController: UIViewController, WKUIDelegate, UIApplicationDelegate, WKNavigationDelegate   {\n\n    @IBOutlet weak var webViewContainer: UIView!\n\n    let requestURLString = "http://google.com/\xe2\x80\x9c\n\n    var webView: WKWebView!\n\n    override func viewDidLoad() {        \n\n        super.viewDidLoad()\n        let webConfiguration = WKWebViewConfiguration()\n\n        let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.webViewContainer.frame.size.height))\n        self.webView = WKWebView (frame: customFrame , configuration: webConfiguration)\n        webView.translatesAutoresizingMaskIntoConstraints = false\n        self.webViewContainer.addSubview(webView)\n        webView.topAnchor.constraint(equalTo: webViewContainer.topAnchor).isActive = true\n        webView.rightAnchor.constraint(equalTo: webViewContainer.rightAnchor).isActive = true\n        webView.leftAnchor.constraint(equalTo: webViewContainer.leftAnchor).isActive = true\n        webView.bottomAnchor.constraint(equalTo: webViewContainer.bottomAnchor).isActive = true\n        webView.heightAnchor.constraint(equalTo: webViewContainer.heightAnchor).isActive = true  \n\n …