Post

Replies

Boosts

Views

Activity

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
772
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
845
Oct ’21
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
845
Jun ’24
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
716
Oct ’21
NSWindow not release memory
Hi, How can I release my NSWindow manually? when the user tap on red close button? @objc func windowWillClose() { // Handle the window closing event here // You can perform any necessary cleanup or ask the user for confirmation // Return true to allow the window to close _window?.contentViewController = nil _window?.delegate = nil _window = nil NotificationCenter.default.removeObserver(self, name: NSWindow.willCloseNotification, object: nil) } //Settings cell tap @objc func settingsItemClicked () { //_window:NSWindow? NotificationCenter.default.addObserver(self, selector: #selector(windowWillClose), name: NSWindow.willCloseNotification, object:_window) if _window?.isVisible == false { // Load the view controller from the storyboard let storyboard = NSStoryboard(name: "Main", bundle: nil) guard let ViewController = storyboard.instantiateController(withIdentifier: "SettingsViewController") as? SettingsViewController else { fatalError("Unable to instantiate SettingsViewController from storyboard.") } // _window.delegate = self // Set the view controller as the content view controller of the window _window?.contentViewController = ViewController _window?.isReleasedWhenClosed = false _window?.hidesOnDeactivate = true // Set the window's title _window?.title = "DynamicLake" // Show the window _window?.makeKeyAndOrderFront(self) }else{ print("The settings view is already open") } }
2
0
1.1k
Aug ’23
Rectangle change size by swipe
Hi,, How can I make a rectangle become taller as I swipe down on my trackpad?" struct BlueRectangleView: View { var body: some View { VStack { Rectangle() .fill(Color.blue) .frame(width: 200, height: 100) .cornerRadius(10) .shadow(radius: 5) .padding() } .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.white) } } struct BlueRectangleView_Previews: PreviewProvider { static var previews: some View { BlueRectangleView() } }
2
0
277
Jan ’25
CABasicAnimation change size of rect
Hi, I'm trying to resize my rect with CABasicAnimation and the animation go to up and not down How can I change it? Video: https://streamable.com/nw4ekc Thank you! let newFrame = NSRect(x: blueRect.frame.origin.x, y: blueRect.frame.origin.y - 100,width: blueRect.frame.size.width, height: 200) let animation = CABasicAnimation(keyPath: "bounds") animation.fromValue = NSValue(rect: blueRect.frame) animation.toValue = NSValue(rect: newFrame) animation.duration = 0.5 // Animation duration in seconds blueRect.layer?.add(animation, forKey: "sizeAnimation") // Update the rect view's size and origin blueRect.frame = newFrame
1
0
1.3k
Jun ’23