Post

Replies

Boosts

Views

Activity

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
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
581
Sep ’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
732
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.2k
Aug ’23