Post

Replies

Boosts

Views

Activity

Reply to Slider .rotationEffect broken in MacOS 14.5
@reindebock Yes, that's a good workaround for vertical sliders. Instead of including the whole SwiftUIIntrospect library, one can also just wrap the NSSlider in a NSViewRepresentable, (as that library presumably does under the hood, along the lines shown for iOS at https://swdevnotes.com/swift/2021/how-to-customise-the-slider-in-swiftui/#documentTop#use-uislider-from-uikit ) Here's a version of that for MacOS: import SwiftUI struct VerticalSlider: NSViewRepresentable { @Binding var value: Double var bounds: ClosedRange<Double> class Coordinator: NSObject { var value: Binding<Double> var bounds: ClosedRange<Double> init(value: Binding<Double>, bounds: ClosedRange<Double> = 0...1) { self.value = value self.bounds = bounds } @objc func valueChanged(_ sender: NSSlider) { self.value.wrappedValue = sender.doubleValue } } func makeCoordinator() -> VerticalSlider.Coordinator { Coordinator(value: $value) } func makeNSView(context: Context) -> NSSlider { let slider = NSSlider(frame: .zero) slider.isVertical = true slider.minValue = bounds.lowerBound slider.maxValue = bounds.upperBound slider.doubleValue = value slider.action = #selector(Coordinator.valueChanged(_:)) slider.target = context.coordinator return slider } func updateNSView(_ nsView: NSSlider, context: Context) { nsView.doubleValue = value } } struct SliderTestView: View { @State var speed = 5.0 var body: some View { VStack() { Text("\(speed)") VerticalSlider(value: $speed, bounds: 1.0...10.0) .onChange(of: speed) { speed in print("\(speed)") } .frame(width: 50, height: 200) } } } #Preview { SliderTestView() }
Jul ’24
Reply to Slider .rotationEffect broken in MacOS 14.5
Yes, I hadn't noticed it before, but I'm seeing that error message too. That's probably a good clue as to what's broken under the hood. Do you also see the button (or "thumb") growing in size as the angle approaches 90°? That suggests that the rotationEffect is using the wrong matrix for any non-zero rotation, even though it only becomes singular at 90° (or multiple thereof). Oddly, other Shapes, like the Rectangles in my example, and even the center line of the Sliders, are rotated correctly, it's only the Slider's thumb that explodes.
Jun ’24
Reply to Default window size does not work for macOS 13 app using SwiftUI
It does work, but only if you haven't run the app previously, such that the system "remembers" a non-default size that was used then, or if you manage to reset that memory. There may be a simpler way to do that, but so far the only reliable way I've found is to: delete the reference to my app in ~/Library/Application\ Support/com.apple.windowmanager/state.plist and resave it delete my app's folder in ~/Library/Containers/ (that's for a sandboxed app, it may otherwise be under Preferences) empty the trash restart the Mac Also, so far I've only tested this with the Window scene rather than WindowGroup. But it was apparently not working with Window either till I managed to clear the previous non-default size using the steps above.
Feb ’23