Post

Replies

Boosts

Views

Activity

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.2k
Aug ’23
Change anchorpoint of NSView without layer
Hi, Is it possible to change the anchorpoint of NSView if I don't use layer? If not how can I use layer and still draw my notch? import Cocoa import Combine class NotchView: NSView { private var mouseDownSubject = PassthroughSubject<NSPoint, Never>() var mouseDownPublisher: AnyPublisher<NSPoint, Never> { return mouseDownSubject.eraseToAnyPublisher() } //Draw notch override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) drawNotch() } func drawNotch () { let size = self.frame.size let r: CGFloat = 16.0 let gap: CGFloat = 1.0 let notch = NSBezierPath() notch.move(to: NSPoint(x: 0.0, y: size.height)) notch.curve(to: NSPoint(x: r, y: size.height - r), controlPoint1: NSPoint(x: r - gap, y: size.height), controlPoint2: NSPoint(x: r, y: size.height - gap)) notch.line(to: NSPoint(x: r, y: r)) notch.curve(to: NSPoint(x: 2 * r, y: 0.0), controlPoint1: NSPoint(x: r, y: gap), controlPoint2: NSPoint(x: r + gap, y: 0.0)) notch.line(to: NSPoint(x: size.width - 2 * r, y: 0.0)) notch.curve(to: NSPoint(x: size.width - r, y: r), controlPoint1: NSPoint(x: size.width - r - gap, y: 0.0), controlPoint2: NSPoint(x: size.width - r, y: gap)) notch.line(to: NSPoint(x: size.width - r, y: size.height - r)) notch.curve(to: NSPoint(x: size.width, y: size.height), controlPoint1: NSPoint(x: size.width - r, y: size.height - gap), controlPoint2: NSPoint(x: size.width - r + gap, y: size.height)) notch.close() NSColor.systemPink.setFill() //change to black to see the notch notch.fill() } //Tap with mouse override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) //move notch to top mouseDownSubject.send(event.locationInWindow) } }
0
0
587
Jul ’23
Animation and position
Hi I'm trying to resize my NSPanel with spring animation but I have a position problem (the panel is not on center of screen) when I make the panel bigger (see the video) How can I fix it? Video: https://streamable.com/l4281l func animationBigger () { let jump = CASpringAnimation(keyPath: "transform.scale") jump.damping = 60 jump.mass = 10 jump.initialVelocity = 10 jump.stiffness = 200.0 jump.fromValue = 1.0 jump.toValue = 2.0 jump.duration = 0.4 //self is NSPanel self.contentView?.layer!.add(jump, forKey: nil) self.setContentSize(bignotchSize) } class NotchView: NSView { private var mouseDownSubject = PassthroughSubject<NSPoint, Never>() var mouseDownPublisher: AnyPublisher<NSPoint, Never> { return mouseDownSubject.eraseToAnyPublisher() } //Draw notch override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) drawNotch() } func drawNotch () { self.layer?.anchorPoint = CGPoint(x: 0.0, y: 0.0) let size = self.frame.size let r: CGFloat = 15.0 let gap: CGFloat = 1.0 let notch = NSBezierPath() notch.move(to: NSPoint(x: 0.0, y: size.height)) notch.curve(to: NSPoint(x: r, y: size.height - r), controlPoint1: NSPoint(x: r - gap, y: size.height), controlPoint2: NSPoint(x: r, y: size.height - gap)) notch.line(to: NSPoint(x: r, y: r)) notch.curve(to: NSPoint(x: 2 * r, y: 0.0), controlPoint1: NSPoint(x: r, y: gap), controlPoint2: NSPoint(x: r + gap, y: 0.0)) notch.line(to: NSPoint(x: size.width - 2 * r, y: 0.0)) notch.curve(to: NSPoint(x: size.width - r, y: r), controlPoint1: NSPoint(x: size.width - r - gap, y: 0.0), controlPoint2: NSPoint(x: size.width - r, y: gap)) notch.line(to: NSPoint(x: size.width - r, y: size.height - r)) notch.curve(to: NSPoint(x: size.width, y: size.height), controlPoint1: NSPoint(x: size.width - r, y: size.height - gap), controlPoint2: NSPoint(x: size.width - r + gap, y: size.height)) notch.close() NSColor.black.setFill() //change to black to see the notch notch.fill() }``` ```language class NotchPanel: NSPanel, CAAnimationDelegate { private (set) var notchView = NotchView() var notchClickPublisher: AnyPublisher<NSPoint, Never> { return notchView.mouseDownPublisher } init(_ center: NSPoint,_ size: NSSize) { let notchFrame = NSRect(x: center.x - 0.5 * size.width, y: center.y - size.height, width: size.width, height: size.height) super.init(contentRect: notchFrame, styleMask: [ .nonactivatingPanel,.nonactivatingPanel, .hudWindow], backing: .buffered, defer: true) self.level = .popUpMenu self.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary] self.isOpaque = true self.isMovable = false //Disable notch to be moveable self.hasShadow = false //we do custom shadow later self.backgroundColor = NSColor.systemPink //notch background setNotchView() } private func setNotchView() { self.contentView?.addSubview(notchView) notchView.translatesAutoresizingMaskIntoConstraints = false notchView.leftAnchor .constraint(equalTo: self.contentView!.leftAnchor) .isActive = true notchView.topAnchor .constraint(equalTo: self.contentView!.topAnchor) .isActive = true notchView.rightAnchor .constraint(equalTo: self.contentView!.rightAnchor) .isActive = true notchView.bottomAnchor .constraint(equalTo: self.contentView!.bottomAnchor) .isActive = true }```
0
0
829
Jun ’23
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
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
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
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
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
Is it possible to get all URL of Safari/Chrome open tabs?
Hi. Is it possible to get all Safari/Chrome open tabs with AppleScript? Is it also possible to check if tab audio is enable/play video/music? macOS Thank you!
Replies
1
Boosts
0
Views
936
Activity
Nov ’23
Handle touchbar volume slider
Hi, Is it possible to handle touchbar volume slider (not volume buttons) I want to print hello when the user use volume slider on touchbar
Replies
0
Boosts
0
Views
571
Activity
Sep ’23
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") } }
Replies
2
Boosts
0
Views
1.2k
Activity
Aug ’23
Airplane mode on watchOS
Hi, Is it possible to turn on airplane mode on watchOS using swift? or possible to know the state of airplane mode? thank you
Replies
1
Boosts
0
Views
1k
Activity
Aug ’23
Change anchorpoint of NSView without layer
Hi, Is it possible to change the anchorpoint of NSView if I don't use layer? If not how can I use layer and still draw my notch? import Cocoa import Combine class NotchView: NSView { private var mouseDownSubject = PassthroughSubject<NSPoint, Never>() var mouseDownPublisher: AnyPublisher<NSPoint, Never> { return mouseDownSubject.eraseToAnyPublisher() } //Draw notch override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) drawNotch() } func drawNotch () { let size = self.frame.size let r: CGFloat = 16.0 let gap: CGFloat = 1.0 let notch = NSBezierPath() notch.move(to: NSPoint(x: 0.0, y: size.height)) notch.curve(to: NSPoint(x: r, y: size.height - r), controlPoint1: NSPoint(x: r - gap, y: size.height), controlPoint2: NSPoint(x: r, y: size.height - gap)) notch.line(to: NSPoint(x: r, y: r)) notch.curve(to: NSPoint(x: 2 * r, y: 0.0), controlPoint1: NSPoint(x: r, y: gap), controlPoint2: NSPoint(x: r + gap, y: 0.0)) notch.line(to: NSPoint(x: size.width - 2 * r, y: 0.0)) notch.curve(to: NSPoint(x: size.width - r, y: r), controlPoint1: NSPoint(x: size.width - r - gap, y: 0.0), controlPoint2: NSPoint(x: size.width - r, y: gap)) notch.line(to: NSPoint(x: size.width - r, y: size.height - r)) notch.curve(to: NSPoint(x: size.width, y: size.height), controlPoint1: NSPoint(x: size.width - r, y: size.height - gap), controlPoint2: NSPoint(x: size.width - r + gap, y: size.height)) notch.close() NSColor.systemPink.setFill() //change to black to see the notch notch.fill() } //Tap with mouse override func mouseDown(with event: NSEvent) { super.mouseDown(with: event) //move notch to top mouseDownSubject.send(event.locationInWindow) } }
Replies
0
Boosts
0
Views
587
Activity
Jul ’23
Animation and position
Hi I'm trying to resize my NSPanel with spring animation but I have a position problem (the panel is not on center of screen) when I make the panel bigger (see the video) How can I fix it? Video: https://streamable.com/l4281l func animationBigger () { let jump = CASpringAnimation(keyPath: "transform.scale") jump.damping = 60 jump.mass = 10 jump.initialVelocity = 10 jump.stiffness = 200.0 jump.fromValue = 1.0 jump.toValue = 2.0 jump.duration = 0.4 //self is NSPanel self.contentView?.layer!.add(jump, forKey: nil) self.setContentSize(bignotchSize) } class NotchView: NSView { private var mouseDownSubject = PassthroughSubject<NSPoint, Never>() var mouseDownPublisher: AnyPublisher<NSPoint, Never> { return mouseDownSubject.eraseToAnyPublisher() } //Draw notch override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) drawNotch() } func drawNotch () { self.layer?.anchorPoint = CGPoint(x: 0.0, y: 0.0) let size = self.frame.size let r: CGFloat = 15.0 let gap: CGFloat = 1.0 let notch = NSBezierPath() notch.move(to: NSPoint(x: 0.0, y: size.height)) notch.curve(to: NSPoint(x: r, y: size.height - r), controlPoint1: NSPoint(x: r - gap, y: size.height), controlPoint2: NSPoint(x: r, y: size.height - gap)) notch.line(to: NSPoint(x: r, y: r)) notch.curve(to: NSPoint(x: 2 * r, y: 0.0), controlPoint1: NSPoint(x: r, y: gap), controlPoint2: NSPoint(x: r + gap, y: 0.0)) notch.line(to: NSPoint(x: size.width - 2 * r, y: 0.0)) notch.curve(to: NSPoint(x: size.width - r, y: r), controlPoint1: NSPoint(x: size.width - r - gap, y: 0.0), controlPoint2: NSPoint(x: size.width - r, y: gap)) notch.line(to: NSPoint(x: size.width - r, y: size.height - r)) notch.curve(to: NSPoint(x: size.width, y: size.height), controlPoint1: NSPoint(x: size.width - r, y: size.height - gap), controlPoint2: NSPoint(x: size.width - r + gap, y: size.height)) notch.close() NSColor.black.setFill() //change to black to see the notch notch.fill() }``` ```language class NotchPanel: NSPanel, CAAnimationDelegate { private (set) var notchView = NotchView() var notchClickPublisher: AnyPublisher<NSPoint, Never> { return notchView.mouseDownPublisher } init(_ center: NSPoint,_ size: NSSize) { let notchFrame = NSRect(x: center.x - 0.5 * size.width, y: center.y - size.height, width: size.width, height: size.height) super.init(contentRect: notchFrame, styleMask: [ .nonactivatingPanel,.nonactivatingPanel, .hudWindow], backing: .buffered, defer: true) self.level = .popUpMenu self.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary] self.isOpaque = true self.isMovable = false //Disable notch to be moveable self.hasShadow = false //we do custom shadow later self.backgroundColor = NSColor.systemPink //notch background setNotchView() } private func setNotchView() { self.contentView?.addSubview(notchView) notchView.translatesAutoresizingMaskIntoConstraints = false notchView.leftAnchor .constraint(equalTo: self.contentView!.leftAnchor) .isActive = true notchView.topAnchor .constraint(equalTo: self.contentView!.topAnchor) .isActive = true notchView.rightAnchor .constraint(equalTo: self.contentView!.rightAnchor) .isActive = true notchView.bottomAnchor .constraint(equalTo: self.contentView!.bottomAnchor) .isActive = true }```
Replies
0
Boosts
0
Views
829
Activity
Jun ’23
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
Replies
1
Boosts
0
Views
1.3k
Activity
Jun ’23
Detect push notification
Hi How can I detect if user get push notification on macOS? Thanks!
Replies
0
Boosts
0
Views
589
Activity
Dec ’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
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
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
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
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
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
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