Post

Replies

Boosts

Views

Activity

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
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
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
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
Check for a new mail (macos)
Hi, How is it possible to check if I have a new mail? Is it possible to do it with ScriptingBridge? Thank you!
Replies
1
Boosts
0
Views
790
Activity
Jan ’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
window level popUpMenu and view behind it
Hi, I'm using NSPanel that his level is .popUpMenu and when I use .quickLookPreview in SwiftUI it make the the Quick Look behind the nspanel how can I fix it without change the level of NSPanel?
Replies
1
Boosts
0
Views
569
Activity
Oct ’24
Application iCloud folder doesn't show in macOS
Hi, I'm working on integrating iCloud Drive functionality into my app. I noticed that the folder for my app appears under /Users/USERNAME/Library/Mobile Documents/MY_CONTAINER, but it doesn't show up in iCloud Drive. Am I missing a step in the setup or configuration? Any guidance would be appreciated! Thanks!
Replies
1
Boosts
0
Views
512
Activity
Dec ’24
Can't run UITests after added iCloud
Hi After I added iCloud container and iCloud documents my UITests can't run anymore what is this problem and how can I solve it? Thanks!
Replies
1
Boosts
0
Views
434
Activity
Dec ’24
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
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
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
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
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
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
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
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
Draw Line animation on macOS
Hi, What is the best way to make this animation with Swift and UIKit? [Animation:](https://dribbble.com/shots/4247369-Loading-notch /) Thank you!
Replies
0
Boosts
0
Views
528
Activity
Dec ’23
How to make Dynamic Island music animation?
How is it possible to remake the Dynamic Island music spectrum (visual EQ) animation on macOS? I see WhatsApp have a similar animation on voice calls. Is there a 3rd or native Apple library to make it? https://imgur.com/a/PKDkosC
Replies
0
Boosts
0
Views
789
Activity
Dec ’23