Skip to content

Commit 3570ec6

Browse files
Luc DionLuc Dion
authored andcommitted
* Fix an issue with pin.vCenter() and pin.hCenter(). These method were wrongly positioning views centered at position 0.
* Update documentation related to these methods. Unit tests will be added later today.
1 parent e97ac71 commit 3570ec6

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

PinLayout/PinLayoutImpl.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class PinLayoutImpl: PinLayout {
157157
@discardableResult
158158
func hCenter() -> PinLayout {
159159
func context() -> String { return "hCenter()" }
160-
setHorizontalCenter(0, context)
160+
guard let layoutSuperview = layoutSuperview(context) else { return self }
161+
setHorizontalCenter(layoutSuperview.frame.width / 2, context)
161162
return self
162163
}
163164

@@ -179,7 +180,8 @@ class PinLayoutImpl: PinLayout {
179180
@discardableResult
180181
func vCenter() -> PinLayout {
181182
func context() -> String { return "vCenter()" }
182-
setVerticalCenter(0, context)
183+
guard let layoutSuperview = layoutSuperview(context) else { return self }
184+
setVerticalCenter(layoutSuperview.frame.height / 2, context)
183185
return self
184186
}
185187

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,17 @@ PinLayout also has shorter version that pins a view’s edge **directly** on its
193193
**Methods**:
194194

195195
* `top()`
196-
Position the view top edge directly on its superview top edge. Similar to calling top(0)
196+
Position the view top edge directly on its superview top edge. Similar to calling `top(0)`.
197197
* `left()`
198-
Position the view left edge directly on its superview top edge. Similar to calling left(0)
198+
Position the view left edge directly on its superview top edge. Similar to calling `left(0)`.
199199
* `bottom()`
200-
Position the view bottom edge directly on its superview top edge. Similar to calling bottom(0)
200+
Position the view bottom edge directly on its superview top edge. Similar to calling `bottom(0)`.
201201
* `right()`
202-
Position the view right edge directly on its superview top edge. Similar to calling right(0)
202+
Position the view right edge directly on its superview top edge. Similar to calling `right(0)`.
203203
* `hCenter()`
204-
Position the view horizontal center directly on its superview horizontal center. Similar to calling hCenter(0).
204+
Position the view horizontal center directly on its superview horizontal center. Similar to calling `hCenter(superview.frame.width / 2)`.
205205
* `vCenter()`
206-
Position the view vertical center directly on its superview vertical center. Similar to calling vCenter(0).
206+
Position the view vertical center directly on its superview vertical center. Similar to calling `hCenter(superview.frame.height / 2)`.
207207

208208
###### Usage examples:
209209
```javascript
@@ -778,6 +778,10 @@ Cell D:
778778

779779
<br>
780780

781+
## Coming soon <a name="coming_soon"></a>
782+
* minWidth/maxWidth, minHeight/maxHeight
783+
*
784+
781785

782786
## FAQ <a name="faq"></a>
783787

0 commit comments

Comments
 (0)