Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/p-x9/touchtracker
👆Show a mark at the touched point on the View of SwiftUI and UIKit.
https://github.com/p-x9/touchtracker
swiftui touch uikit
Last synced: 3 months ago
JSON representation
👆Show a mark at the touched point on the View of SwiftUI and UIKit.
- Host: GitHub
- URL: https://github.com/p-x9/touchtracker
- Owner: p-x9
- License: mit
- Created: 2023-04-12T15:18:54.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-29T14:51:50.000Z (over 1 year ago)
- Last Synced: 2024-10-11T22:50:29.010Z (4 months ago)
- Topics: swiftui, touch, uikit
- Language: Swift
- Homepage: https://p-x9.github.io/TouchTracker/documentation/touchtracker/
- Size: 122 KB
- Stars: 37
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TouchTracker
Show a mark at the touched point on the View of SwiftUI.
## Demo
https://user-images.githubusercontent.com/50244599/231504004-e1a1e815-3156-4f03-ba52-316afa061781.MP4
## Document
Set the following for a View of SwiftUI.
```swift
Text("Hello")
.touchTrack()
```
Alternatively, it can also be written as follows
```swift
TouchTrackingView {
Text("Hello")
}
```### Customize
```swift
Text("Hello")
.touchTrack() // show touch point
.touchPointRadius(8) // radius of mark on touched point
.touchPointOffset(x: 0, y: -10) // offset of mark position
.touchPointColor(.orange) // color of mark on touched point
.touchPointBorder(true, color: .blue, width: 1) // applying a border to touched points
.touchPointShadow(true, color: .purple, radius: 3) // shadow on touched points
.touchPointDisplayMode(.recordingOnly) // display mode of touched points
.showLocationLabel(true) // show touch coordinate
```
![Example](https://user-images.githubusercontent.com/50244599/231509731-d3ea5df0-1981-4911-9a14-2b57bf575eb7.PNG)It is also possible to display images as follow
```swift
Text("Hello")
.touchPointImage(Image(systemName: "swift").resizable())
```
![Example2](https://user-images.githubusercontent.com/50244599/231510854-c1669ba5-2071-446d-8cda-5131bce14511.PNG)### UIKit
If you want to adapt it to the entire app created with UIKit, write the following.
Use a view named `TouchTrackingUIView`
```swift
import TouchTrackerclass AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let v = TouchTrackingUIView(isShowLocation: true)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if let window {
window.addSubview(v)
v.translatesAutoresizingMaskIntoConstraints = falseNSLayoutConstraint.activate([
v.topAnchor.constraint(equalTo: window.topAnchor),
v.bottomAnchor.constraint(equalTo: window.bottomAnchor),
v.leftAnchor.constraint(equalTo: window.leftAnchor),
v.rightAnchor.constraint(equalTo: window.rightAnchor),
])
}
return true
}
```#### Propagate touch events to other windows
The following configuration allows you to share a touch event received in one window with other windows.```swift
v.shouldPropagateEventAcrossWindows = true
```In the given configuration, even when windows overlap, typically only one window receives a touch event.
Moreover, if a touch event starts in one window, such as Window A, it will only be responsive in Window A, even if it moves to another window, like Window B.Therefore, the touch event can be shared so that the marker of the tapped point will be displayed in the other window even in such a case.
## License
TouchTracker is released under the MIT License. See [LICENSE](./LICENSE)