-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make
anchorPoint
a UnitPoint
instead of CGPoint
`UnitPoint` - https://developer.apple.com/documentation/swiftui/unitpoint - is more SwiftUI-y than `CGPoint`, and will allow the anchorPoint to use the constants like `.center` and `.bottom`. Extract extensions to make it trivial to convert the `UnitPoint` to a `centerOffset` within a rect, and to convert back to a `CGPoint` for the `UIView` `anchorPoint` property.
- Loading branch information
1 parent
8d08f92
commit f9dce1b
Showing
3 changed files
with
32 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by Darron Schall on 10/2/23. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension UnitPoint { | ||
|
||
func toCGPoint() -> CGPoint { | ||
return CGPoint(x: x, y: y) | ||
} | ||
|
||
func toCenterOffset(in rect: CGRect) -> CGPoint { | ||
return CGPoint( | ||
x: (0.5 - x) * rect.width, | ||
y: (0.5 - y) * rect.height | ||
) | ||
} | ||
|
||
} | ||
|
||
|