Post

Replies

Boosts

Views

Activity

Can't typing on NSTextField
Hi, I just did a NSTextField with auto complete that show a cities menu bar the problem is when I typing the first letter, the focus change to the menubar and if I try to write another letter it just replace the first letter and not add it how can I fix it? Thank you! class NSTextFieldAuto: NSTextField, NSMenuDelegate, NSTextFieldDelegate { var suggestionMenu: NSMenu? var selectedSuggestionIndex: Int? override func awakeFromNib() { super.awakeFromNib() self.delegate = self self.suggestionMenu = NSMenu() self.suggestionMenu?.delegate = self } override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) // Deselect all text when the text field is clicked } override func textDidChange(_ notification: Notification) { super.textDidChange(notification) print("Still typing") updateSuggestionMenu() showSuggestionMenu() } override func textDidEndEditing(_ notification: Notification) { print("Finished typing") cityDef.setValue(self.stringValue, forKey: cityDefKey) } func updateSuggestionMenu() { self.suggestionMenu?.removeAllItems() let searchText = self.stringValue.lowercased() for (index, city) in allCities.enumerated() { if city.lowercased().hasPrefix(searchText) { let item = NSMenuItem(title: city, action: #selector(selectSuggestion(_:)), keyEquivalent: "") item.target = self self.suggestionMenu?.addItem(item) } } } func showSuggestionMenu() { if let menu = self.suggestionMenu, !menu.items.isEmpty { let textFieldRect = self.bounds let origin = NSPoint(x: textFieldRect.origin.x + 100.0, y: textFieldRect.origin.y + textFieldRect.size.height) menu.autoenablesItems = false menu.popUp(positioning: nil, at: origin, in: self) } } @objc func selectSuggestion(_ sender: NSMenuItem) { self.stringValue = sender.title } override func cancelOperation(_ sender: Any?) { self.suggestionMenu?.cancelTracking() self.window?.becomeFirstResponder() } func menuDidClose(_ menu: NSMenu) { self.window?.makeFirstResponder(self) // Set text field as first responder again print("Close menu") } override func becomeFirstResponder() -> Bool { let result = super.becomeFirstResponder() self.selectedSuggestionIndex = nil // Reset selected suggestion index return result } }
Topic: UI Frameworks SubTopic: AppKit Tags:
3
0
866
Jun ’24
contextMenu and right click
Hi, I made a "Finder view" with SwiftUI, how is it possible to call viewModel.selectFileWithAnimation(file) when .contextMenu show? Thank you! @StateObject private var viewModel = FilesViewModel() // Use the view model to manage data and logic var body: some View { VStack { // Horizontal scrolling of files and folders ScrollView(.horizontal, showsIndicators: false) { if viewModel.sortedAndFilteredFolderContents.isEmpty { // Show "No Results" if no files or folders found Text("No Results") .font(.headline) .foregroundColor(.almostWhite) .padding() } else { HStack(spacing: 20) { ForEach(viewModel.sortedAndFilteredFolderContents, id: \.self) { file in VStack { ZStack { // Selection effect without matchedGeometryEffect if viewModel.selectedFile == file { RoundedRectangle(cornerRadius: 10) .fill(Color.blue.opacity(0.2)) .transition(.opacity) .frame(width: 80, height: 100) .animation(.easeInOut(duration: 0.3), value: viewModel.selectedFile) } VStack { Image(nsImage: viewModel.getFileIcon(for: file)) .resizable() .frame(width: 64, height: 64) .onTapGesture(count: 2) { // Select and open file/folder on double-tap viewModel.selectFileWithAnimation(file) viewModel.openFileOrFolder(file) } .onTapGesture { viewModel.selectFileWithAnimation(file) } .onLongPressGesture(minimumDuration: 0.5) { // Rename file with long press viewModel.rename(file) } .contextMenu { // Define your context menu buttons here Button(action: { viewModel.showInFinder(file) }) { Text("Show in Finder") Image(systemName: "folder") } Button(action: { viewModel.moveToTrash(file) }) { Text("Move to Trash") Image(systemName: "trash") } Button(action: { viewModel.rename(file) }) { Text("Rename") Image(systemName: "pencil") } Button(action: { viewModel.makeAlias(for: file) }) { Text("Make Alias") Image(systemName: "link") } Button(action: { viewModel.compress(file) }) { Text("Compress \(file.lastPathComponent)") Image(systemName: "archivebox") } Button(action: { viewModel.copyFile(file) }) { Text("Copy") Image(systemName: "doc.on.doc") } Button(action: { viewModel.shareFile(file, in: dynaClip.view) }) { Text("Share") Image(systemName: "square.and.arrow.up") } } Text(file.lastPathComponent) .font(.caption) .lineLimit(1) .truncationMode(.tail) .frame(width: 80) } } } } } .padding(.top, 20) } }
1
0
591
Sep ’24
Screen blinking when key press
Hi, I override keyUp function to detect if the space key is press everything works but the screen blink with a white flash every time I press space key how can I fix it? override func keyUp(with event: NSEvent) {     //Tap on escape 0x31 = Space     if event.keyCode == UInt16(0x31){       print("Hello")     }   }
3
0
792
Oct ’21
NSImageView with corner radius and shadow
Hi, I'm trying to add a drop shadow for NSImageView with NSBeizerPath but the shadow does not appear //add cgPath var to NSBezierPath extension NSBezierPath {   public var cgPath: CGPath {     let path = CGMutablePath()     var points = [CGPoint](repeating: .zero, count: 3)     for i in 0 ..< elementCount {       let type = element(at: i, associatedPoints: &points)       switch type {       case .moveTo:         path.move(to: points[0])       case .lineTo:         path.addLine(to: points[0])       case .curveTo:         path.addCurve(to: points[2], control1: points[0], control2: points[1])       case .closePath:         path.closeSubpath()       @unknown default:         continue       }     }     return path   } } //View var albumImage = NSImageView()        albumImage.layer?.shadowRadius = 10.0       albumImage.layer?.shadowColor = .black       albumImage.layer?.shadowOffset = CGSize(width: 10, height: 10)       albumImage.layer?.shadowOpacity = 1.0       albumImage.layer?.shadowPath = NSBezierPath(roundedRect: albumImage.bounds, xRadius: 28.0, yRadius: 28.0).cgPath
3
0
861
Oct ’21
Cant click on buttons after update to Xcode 13
Hi, I just updated to macOS Monterey and Xcode 13.1 and the NSButtons on my view not work anymore I tap and nothing work    let visualEffect = NSVisualEffectView()     //var theme = NSAppearance(appearanceNamed: NSAppearance.Name.vibrantDark, bundle: nil)     visualEffect.translatesAutoresizingMaskIntoConstraints = false     visualEffect.blendingMode = .behindWindow     visualEffect.state = .active     visualEffect.wantsLayer = true     visualEffect.layer?.cornerRadius = roundvalueDefault.value(forKey: "roundvaluekey") as! CGFloat     visualEffect.layer?.opacity = 0.0     window?.isOpaque = false     window?.backgroundColor = .clear //Make window transpraent     window?.isMovableByWindowBackground = true     checkAlt() //Check if floating           //Custom toolbar     let customToolbar = NSToolbar()     customToolbar.isVisible = true     window?.titleVisibility = .hidden     window?.styleMask.insert(.fullSizeContentView)     window?.titlebarAppearsTransparent = true     customToolbar.showsBaselineSeparator = false     window?.contentView?.wantsLayer = true     window?.toolbar = customToolbar           //Change windows radius           //Add the blur effcet to the window     window?.contentView?.addSubview(visualEffect)           guard let constraints = window?.contentView else {      return     }     visualEffect.leadingAnchor.constraint(equalTo: constraints.leadingAnchor).isActive = true     visualEffect.trailingAnchor.constraint(equalTo: constraints.trailingAnchor).isActive = true     visualEffect.topAnchor.constraint(equalTo: constraints.topAnchor).isActive = true     visualEffect.bottomAnchor.constraint(equalTo: constraints.bottomAnchor).isActive = true   }  @IBAction func airplayTapped(_ sender: Any) {     print("AAA")   }
2
0
737
Oct ’21
Airplay (music) not works
Hi, I just add airplay to my app and I tried to stream to my TV but not works AirPlay code:   //Airplay button     let routePickerView = AVRoutePickerView.init(frame: airplayButton.frame)     routePickerView.isRoutePickerButtonBordered = false     self.view.addSubview(routePickerView)let asset = AVAsset(url: URL(string: "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8")!)
0
0
568
Nov ’21
How can I capture audio samples output on macOS?
I'm trying to capture audio samples from the selected output device on macOS using ScreenCaptureKit? Thank you
Replies
2
Boosts
0
Views
1.3k
Activity
Jun ’24
Can't typing on NSTextField
Hi, I just did a NSTextField with auto complete that show a cities menu bar the problem is when I typing the first letter, the focus change to the menubar and if I try to write another letter it just replace the first letter and not add it how can I fix it? Thank you! class NSTextFieldAuto: NSTextField, NSMenuDelegate, NSTextFieldDelegate { var suggestionMenu: NSMenu? var selectedSuggestionIndex: Int? override func awakeFromNib() { super.awakeFromNib() self.delegate = self self.suggestionMenu = NSMenu() self.suggestionMenu?.delegate = self } override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) // Deselect all text when the text field is clicked } override func textDidChange(_ notification: Notification) { super.textDidChange(notification) print("Still typing") updateSuggestionMenu() showSuggestionMenu() } override func textDidEndEditing(_ notification: Notification) { print("Finished typing") cityDef.setValue(self.stringValue, forKey: cityDefKey) } func updateSuggestionMenu() { self.suggestionMenu?.removeAllItems() let searchText = self.stringValue.lowercased() for (index, city) in allCities.enumerated() { if city.lowercased().hasPrefix(searchText) { let item = NSMenuItem(title: city, action: #selector(selectSuggestion(_:)), keyEquivalent: "") item.target = self self.suggestionMenu?.addItem(item) } } } func showSuggestionMenu() { if let menu = self.suggestionMenu, !menu.items.isEmpty { let textFieldRect = self.bounds let origin = NSPoint(x: textFieldRect.origin.x + 100.0, y: textFieldRect.origin.y + textFieldRect.size.height) menu.autoenablesItems = false menu.popUp(positioning: nil, at: origin, in: self) } } @objc func selectSuggestion(_ sender: NSMenuItem) { self.stringValue = sender.title } override func cancelOperation(_ sender: Any?) { self.suggestionMenu?.cancelTracking() self.window?.becomeFirstResponder() } func menuDidClose(_ menu: NSMenu) { self.window?.makeFirstResponder(self) // Set text field as first responder again print("Close menu") } override func becomeFirstResponder() -> Bool { let result = super.becomeFirstResponder() self.selectedSuggestionIndex = nil // Reset selected suggestion index return result } }
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
3
Boosts
0
Views
866
Activity
Jun ’24
contextMenu and right click
Hi, I made a "Finder view" with SwiftUI, how is it possible to call viewModel.selectFileWithAnimation(file) when .contextMenu show? Thank you! @StateObject private var viewModel = FilesViewModel() // Use the view model to manage data and logic var body: some View { VStack { // Horizontal scrolling of files and folders ScrollView(.horizontal, showsIndicators: false) { if viewModel.sortedAndFilteredFolderContents.isEmpty { // Show "No Results" if no files or folders found Text("No Results") .font(.headline) .foregroundColor(.almostWhite) .padding() } else { HStack(spacing: 20) { ForEach(viewModel.sortedAndFilteredFolderContents, id: \.self) { file in VStack { ZStack { // Selection effect without matchedGeometryEffect if viewModel.selectedFile == file { RoundedRectangle(cornerRadius: 10) .fill(Color.blue.opacity(0.2)) .transition(.opacity) .frame(width: 80, height: 100) .animation(.easeInOut(duration: 0.3), value: viewModel.selectedFile) } VStack { Image(nsImage: viewModel.getFileIcon(for: file)) .resizable() .frame(width: 64, height: 64) .onTapGesture(count: 2) { // Select and open file/folder on double-tap viewModel.selectFileWithAnimation(file) viewModel.openFileOrFolder(file) } .onTapGesture { viewModel.selectFileWithAnimation(file) } .onLongPressGesture(minimumDuration: 0.5) { // Rename file with long press viewModel.rename(file) } .contextMenu { // Define your context menu buttons here Button(action: { viewModel.showInFinder(file) }) { Text("Show in Finder") Image(systemName: "folder") } Button(action: { viewModel.moveToTrash(file) }) { Text("Move to Trash") Image(systemName: "trash") } Button(action: { viewModel.rename(file) }) { Text("Rename") Image(systemName: "pencil") } Button(action: { viewModel.makeAlias(for: file) }) { Text("Make Alias") Image(systemName: "link") } Button(action: { viewModel.compress(file) }) { Text("Compress \(file.lastPathComponent)") Image(systemName: "archivebox") } Button(action: { viewModel.copyFile(file) }) { Text("Copy") Image(systemName: "doc.on.doc") } Button(action: { viewModel.shareFile(file, in: dynaClip.view) }) { Text("Share") Image(systemName: "square.and.arrow.up") } } Text(file.lastPathComponent) .font(.caption) .lineLimit(1) .truncationMode(.tail) .frame(width: 80) } } } } } .padding(.top, 20) } }
Replies
1
Boosts
0
Views
591
Activity
Sep ’24
Implement vibrancy on NSTextField
Hi, How can I make NSTextField vibracny? I added a NSVisualEffectView and add a label how can I make my label vibrancy https://imgur.com/a/Y6axxms Thanks!
Replies
2
Boosts
0
Views
774
Activity
Aug ’21
NSButton vibrancy not working on light mode
Hi, I'm using NSButton and the vibrancy effect works only when the system is in dark mode How can I get a vibrancy effect also on light mode?
Replies
0
Boosts
0
Views
423
Activity
Aug ’21
Play/Pause now playing with MediaRemote framework
Hi, How can I pause/play the now playing song with MedaiRemote framework Thanks!
Replies
1
Boosts
0
Views
1.1k
Activity
Aug ’21
How to import Apple private framework
HI, Is it possible to add a private framework to the project? I tried to import MediaRemote.framework but Xcode does not find the framework also when I added the path to the framework in Framework linker
Replies
0
Boosts
0
Views
622
Activity
Aug ’21
How to override shadowColor?
Hi, How can I override property shadowColor from NSShadow? thanks!
Replies
1
Boosts
0
Views
498
Activity
Sep ’21
Autoscroll NSTextField (left to right)
Hi, How can make auto-scroll label with NSTextField like in the iTunes app? Thanks!
Replies
0
Boosts
0
Views
548
Activity
Oct ’21
Screen blinking when key press
Hi, I override keyUp function to detect if the space key is press everything works but the screen blink with a white flash every time I press space key how can I fix it? override func keyUp(with event: NSEvent) {     //Tap on escape 0x31 = Space     if event.keyCode == UInt16(0x31){       print("Hello")     }   }
Replies
3
Boosts
0
Views
792
Activity
Oct ’21
AirPlay available devices list?
Hi, How can I show the avaliable list device for AirPlay like this?
Replies
4
Boosts
0
Views
1k
Activity
Oct ’21
NSImageView with corner radius and shadow
Hi, I'm trying to add a drop shadow for NSImageView with NSBeizerPath but the shadow does not appear //add cgPath var to NSBezierPath extension NSBezierPath {   public var cgPath: CGPath {     let path = CGMutablePath()     var points = [CGPoint](repeating: .zero, count: 3)     for i in 0 ..< elementCount {       let type = element(at: i, associatedPoints: &points)       switch type {       case .moveTo:         path.move(to: points[0])       case .lineTo:         path.addLine(to: points[0])       case .curveTo:         path.addCurve(to: points[2], control1: points[0], control2: points[1])       case .closePath:         path.closeSubpath()       @unknown default:         continue       }     }     return path   } } //View var albumImage = NSImageView()        albumImage.layer?.shadowRadius = 10.0       albumImage.layer?.shadowColor = .black       albumImage.layer?.shadowOffset = CGSize(width: 10, height: 10)       albumImage.layer?.shadowOpacity = 1.0       albumImage.layer?.shadowPath = NSBezierPath(roundedRect: albumImage.bounds, xRadius: 28.0, yRadius: 28.0).cgPath
Replies
3
Boosts
0
Views
861
Activity
Oct ’21
Cant click on buttons after update to Xcode 13
Hi, I just updated to macOS Monterey and Xcode 13.1 and the NSButtons on my view not work anymore I tap and nothing work    let visualEffect = NSVisualEffectView()     //var theme = NSAppearance(appearanceNamed: NSAppearance.Name.vibrantDark, bundle: nil)     visualEffect.translatesAutoresizingMaskIntoConstraints = false     visualEffect.blendingMode = .behindWindow     visualEffect.state = .active     visualEffect.wantsLayer = true     visualEffect.layer?.cornerRadius = roundvalueDefault.value(forKey: "roundvaluekey") as! CGFloat     visualEffect.layer?.opacity = 0.0     window?.isOpaque = false     window?.backgroundColor = .clear //Make window transpraent     window?.isMovableByWindowBackground = true     checkAlt() //Check if floating           //Custom toolbar     let customToolbar = NSToolbar()     customToolbar.isVisible = true     window?.titleVisibility = .hidden     window?.styleMask.insert(.fullSizeContentView)     window?.titlebarAppearsTransparent = true     customToolbar.showsBaselineSeparator = false     window?.contentView?.wantsLayer = true     window?.toolbar = customToolbar           //Change windows radius           //Add the blur effcet to the window     window?.contentView?.addSubview(visualEffect)           guard let constraints = window?.contentView else {      return     }     visualEffect.leadingAnchor.constraint(equalTo: constraints.leadingAnchor).isActive = true     visualEffect.trailingAnchor.constraint(equalTo: constraints.trailingAnchor).isActive = true     visualEffect.topAnchor.constraint(equalTo: constraints.topAnchor).isActive = true     visualEffect.bottomAnchor.constraint(equalTo: constraints.bottomAnchor).isActive = true   }  @IBAction func airplayTapped(_ sender: Any) {     print("AAA")   }
Replies
2
Boosts
0
Views
737
Activity
Oct ’21
How to add vibrancy to image?
Hi, How can I add vibrancy to image/NSButton for example my play button (macOS) I found a SwiftUI library for this but I don't use swift UI https://github.com/lucasbrown/swiftui-visual-effects My app
Replies
1
Boosts
0
Views
856
Activity
Nov ’21
Airplay (music) not works
Hi, I just add airplay to my app and I tried to stream to my TV but not works AirPlay code:   //Airplay button     let routePickerView = AVRoutePickerView.init(frame: airplayButton.frame)     routePickerView.isRoutePickerButtonBordered = false     self.view.addSubview(routePickerView)let asset = AVAsset(url: URL(string: "https://bitdash-a.akamaihd.net/content/MI201109210084_1/m3u8s/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.m3u8")!)
Replies
0
Boosts
0
Views
568
Activity
Nov ’21