Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Material
Commits
c0675fa4
Commit
c0675fa4
authored
Oct 28, 2018
by
Orkhan Alikhanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added safe area guide support
parent
d8e312ae
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
8 deletions
+33
-8
Sources/iOS/Layout.swift
+29
-5
Sources/iOS/LayoutAnchor.swift
+4
-3
No files found.
Sources/iOS/Layout.swift
View file @
c0675fa4
...
@@ -31,6 +31,13 @@
...
@@ -31,6 +31,13 @@
import
UIKit
import
UIKit
import
Motion
import
Motion
/// A protocol that's conformed by UIView and UILayoutGuide.
public
protocol
Layoutable
:
class
{
}
@available(iOS 9.0, *)
extension
UILayoutGuide
:
Layoutable
{
}
extension
UIView
:
Layoutable
{
}
/// Layout extension for UIView.
/// Layout extension for UIView.
public
extension
UIView
{
public
extension
UIView
{
/**
/**
...
@@ -48,22 +55,34 @@ public extension UIView {
...
@@ -48,22 +55,34 @@ public extension UIView {
var
layout
:
Layout
{
var
layout
:
Layout
{
return
Layout
(
view
:
self
)
return
Layout
(
view
:
self
)
}
}
/**
Layout instance for safeAreaLayoutGuide.
Below iOS 11, it will be same as view.layout.
*/
var
safeLayout
:
Layout
{
if
#available(iOS 11.0, *)
{
return
Layout
(
view
:
safeAreaLayoutGuide
)
}
else
{
return
layout
}
}
}
}
public
struct
Layout
{
public
struct
Layout
{
/// A weak reference to the view.
/// A weak reference to the view.
weak
var
view
:
UIView
?
weak
var
view
:
Layoutable
?
/// Parent view of the view.
/// Parent view of the view.
var
parent
:
UIView
?
{
var
parent
:
UIView
?
{
return
view
?
.
superview
return
(
view
as?
UIView
)
?
.
superview
}
}
/**
/**
An initializer taking UIView.
An initializer taking UIView.
- Parameter view: A UIView.
- Parameter view: A UIView.
*/
*/
init
(
view
:
UIView
)
{
init
(
view
:
Layoutable
)
{
self
.
view
=
view
self
.
view
=
view
}
}
}
}
...
@@ -516,10 +535,15 @@ private extension Layout {
...
@@ -516,10 +535,15 @@ private extension Layout {
*/
*/
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
to
anchor
:
LayoutAnchorable
,
constants
:
[
CGFloat
])
->
Layout
{
func
constraint
(
_
attributes
:
[
LayoutAttribute
],
to
anchor
:
LayoutAnchorable
,
constants
:
[
CGFloat
])
->
Layout
{
let
from
=
LayoutAnchor
(
view
:
view
,
attributes
:
attributes
)
let
from
=
LayoutAnchor
(
view
:
view
,
attributes
:
attributes
)
let
to
=
anchor
as?
LayoutAnchor
??
LayoutAnchor
(
view
:
anchor
as?
UIV
iew
,
attributes
:
attributes
)
let
to
=
anchor
as?
LayoutAnchor
??
LayoutAnchor
(
view
:
(
anchor
as?
UIView
)
??
(
anchor
as?
Layout
)?
.
v
iew
,
attributes
:
attributes
)
let
constraint
=
LayoutConstraint
(
fromAnchor
:
from
,
toAnchor
:
to
,
constants
:
constants
)
let
constraint
=
LayoutConstraint
(
fromAnchor
:
from
,
toAnchor
:
to
,
constants
:
constants
)
let
constraints
=
(
view
?
.
constraints
??
[])
+
(
parent
?
.
constraints
??
[])
var
v
=
view
as?
UIView
if
#available(iOS 9.0, *)
,
v
==
nil
{
v
=
(
view
as?
UILayoutGuide
)?
.
owningView
}
let
constraints
=
(
v
?
.
constraints
??
[])
+
(
v
?
.
superview
?
.
constraints
??
[])
let
newConstraints
=
constraint
.
constraints
let
newConstraints
=
constraint
.
constraints
for
newConstraint
in
newConstraints
{
for
newConstraint
in
newConstraints
{
guard
let
activeConstraint
=
constraints
.
first
(
where
:
{
$0
.
equalTo
(
newConstraint
)
})
else
{
guard
let
activeConstraint
=
constraints
.
first
(
where
:
{
$0
.
equalTo
(
newConstraint
)
})
else
{
...
...
Sources/iOS/LayoutAnchor.swift
View file @
c0675fa4
...
@@ -30,15 +30,16 @@
...
@@ -30,15 +30,16 @@
import
UIKit
import
UIKit
/// A protocol that's conformed by UIView
and LayoutAnchor
.
/// A protocol that's conformed by UIView
, LayoutAnchor, and Layout
.
public
protocol
LayoutAnchorable
{
}
public
protocol
LayoutAnchorable
{
}
extension
UIView
:
LayoutAnchorable
{
}
extension
UIView
:
LayoutAnchorable
{
}
extension
Layout
:
LayoutAnchorable
{
}
extension
LayoutAnchor
:
LayoutAnchorable
{
}
extension
LayoutAnchor
:
LayoutAnchorable
{
}
public
struct
LayoutAnchor
{
public
struct
LayoutAnchor
{
/// A weak reference to the view.
/// A weak reference to the view.
weak
var
view
:
UIView
?
weak
var
view
:
Layoutable
?
/// An array of LayoutAttribute for the view.
/// An array of LayoutAttribute for the view.
let
attributes
:
[
LayoutAttribute
]
let
attributes
:
[
LayoutAttribute
]
...
@@ -48,7 +49,7 @@ public struct LayoutAnchor {
...
@@ -48,7 +49,7 @@ public struct LayoutAnchor {
- Parameter view: A UIView.
- Parameter view: A UIView.
- Parameter attributes: An array of LayoutAtrribute.
- Parameter attributes: An array of LayoutAtrribute.
*/
*/
init
(
view
:
UIView
?,
attributes
:
[
LayoutAttribute
])
{
init
(
view
:
Layoutable
?,
attributes
:
[
LayoutAttribute
])
{
self
.
view
=
view
self
.
view
=
view
self
.
attributes
=
attributes
self
.
attributes
=
attributes
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment