uiviewrepresentable

How do I get my UIView to correctly size for its content in SwiftUI?

十年热恋 提交于 2020-05-17 02:57:13
问题 I want to use the awesome MultiSegmentPicker written by Yonat Sharon in my SwiftUI View. https://github.com/yonat/MultiSelectSegmentedControl However, I don't fully understand the interaction between the UIViewRepresentable View and my SwiftUI View. How do I get the host view controller to shrink its height down to the size of the segmented control? Here's the debugger view of the demo page - notice the blue area around the top bar: The demo code doesn't give a lot of insight into the issue,

How to render multiline text in SwiftUI List with correct height?

我怕爱的太早我们不能终老 提交于 2020-05-14 18:42:07
问题 I would like to have a SwiftUI view that shows many lines of text, with the following requirements: Works on both macOS and iOS. Shows a large number of strings (each string is backed by a separate model object). I can do arbitrary styling to the multiline text. Each string of text can be of arbitrary length, possibly spanning multiple lines and paragraphs. The maximum width of each string of text is fixed to the width of the container. Height is variable according to the actual length of

evaluateJavaScript in swiftui

拥有回忆 提交于 2020-04-16 03:32:09
问题 How to get evaluateJavaScript to work when a message is received from webview? print(message.body) <--- this is working parent?.evaluateJavaScript("document.getElementsByClassName('mat-toolbar-single-row')[0].style.backgroundColor = 'red'", completionHandler: nil) <--- this is not struct WebView: UIViewRepresentable { let request: URLRequest let contentController = ContentController(nil) func makeUIView(context: Context) -> WKWebView { let webConfiguration = WKWebViewConfiguration() let

SKView warning logs

a 夏天 提交于 2020-02-02 02:33:27
问题 When running my SwiftUI & SpriteKit app, I get the following messages in the logs: 2019-11-18 21:58:57.631912+0000 PixelBattles[2812:1215803] SKView: ignoreRenderSyncInLayoutSubviews is NO. Call _renderSynchronouslyForTime without handler What am I doing wrong to receive this log, and should I worry about it? Could it be a bug? Could it be that SwiftUI cannot figure out how to do the layout for an SKView ? Major edit: If you need code, you can see it in the previous edits. Below I state why I

SKView warning logs

给你一囗甜甜゛ 提交于 2020-02-02 02:32:36
问题 When running my SwiftUI & SpriteKit app, I get the following messages in the logs: 2019-11-18 21:58:57.631912+0000 PixelBattles[2812:1215803] SKView: ignoreRenderSyncInLayoutSubviews is NO. Call _renderSynchronouslyForTime without handler What am I doing wrong to receive this log, and should I worry about it? Could it be a bug? Could it be that SwiftUI cannot figure out how to do the layout for an SKView ? Major edit: If you need code, you can see it in the previous edits. Below I state why I

SwiftUI - State change in UITextField causes the frameWidth to grow uncontrolled and ignore bounds/frame

余生颓废 提交于 2020-01-21 18:07:07
问题 I am using SwiftUI and bridge to UITextField (I need to assign firstResponder). I use the code from here: SwiftUI: How to make TextField become first responder? The following code updates my @Binding var. This of course is intended behavior. The problem is that this causes the textField to ignore the frame/ bounds. It just expands and pushes other elements out of the view. Other parts of the view are also reliant on the @State. func textFieldDidChangeSelection(_ textField: UITextField) { text

PencilKit in SwiftUI

ぃ、小莉子 提交于 2020-01-06 04:51:52
问题 I'm trying to use PencilKit in SwiftUI. How can I detect in the updateUIView -function, which Binding -variable was updated? For example I don't want to clear the canvas when changing the color. And is there a better way to clear the canvas than toggling a boolean? Toggling a boolean forces the updateUIView -function to execute. import SwiftUI import UIKit import PencilKit struct ContentView: View { @State var color = UIColor.black @State var clear = false var body: some View { VStack{