Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Safe Area Layout Guide and Visual Format Language

I want to use Apples visual format language to constrain a view to the new Safe Area Layout Guide in iOS 11. However, I get an exception:

-[NSLayoutYAxisAnchor nsli_superitem]: unrecognized selector sent to instance 0x1c447ed40

    //Make View Dictionary     var views: [String: Any] = ["left": self.leftContainer]      //Check swift version and add appropriate piece to the view dictionary     if #available(iOS 11, *) {         views["topGuide"] = self.view.safeAreaLayoutGuide.topAnchor     }else{         views["topGuide"] = self.topLayoutGuide     }      //Make the constraint using visual format language     let leftVertical = NSLayoutConstraint.constraints(withVisualFormat: "V:[topGuide][left]|", options: [], metrics: nil, views: views)      //Add the new constraint     self.view.addConstraints(vertical) 

The reason I like visual format language is because you a can add lot of constraints with less code in some cases.

Any Ideas?

like image 467
Jon Vogel Avatar asked Sep 28 '17 22:09

Jon Vogel


People also ask

What is safe area layout guide?

The Safe Area layout guide represents the portion of the screen that is not covered by the navigation bars, tab bars, and toolbars.

How do I disable safe area layout guide?

You can disable safe area layout guide from storyboard for particular view controller. Select View Controller -> File Inspector (first tab) -> Use safe area layout guides (uncheck the checkbox).

What is safe area in Swift?

A safe area defines the area within a view that isn't covered by a navigation bar, tab bar, toolbar, or other views. SwiftUI views respect safe areas out of the box. But there are plenty of situations when you need to customize this behavior.

What is visual format?

In CSS The Visual Formatting Model describes how user agents take the document tree, and process and display it for visual media. This includes continuous media such as a computer screen and paged media such as a book or document printed by browser print functions.


1 Answers

I want to use Apples visual format language to constrain a view to the new Safe Area Layout Guide

You can't. There is no access to the safe area layout guide through the visual format language. I've filed a bug on this, and I suggest you do the same.

like image 167
matt Avatar answered Sep 25 '22 05:09

matt