Note: This does not happen on MacOS 13 and older.
I have a NSView (parent) and multiple subviews (child nsviews). When I animate the frame of the subviews ex: [[view animator] setFrame:frame] to move them outside the parent view's frame, the contents of the subviews disappear/clipped before the animation starts. This started happening after installing Sonoma. I tried setting clipsToBounds to false and it did not make any difference.
Is anyone else seeing this behavior in Sonoma?
Why does appkit clip the contents before the animation starts? Is there a way to switch it to "clip after animation ends" ?
AppKit
RSS for tagConstruct and manage a graphical, event-driven user interface for your macOS app using AppKit.
Posts under AppKit tag
196 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
I currently have a toolbar item group with 3 items, but clicking on any of the items doesn't do anything. Also none of the items appear to be highlighted, not even when manually setting NSToolbarItemGroup.selectedIndex. What am I missing? Setting the action property on the individual items rather than the group makes the items clickable, but still none of them appear to be selected.
class ViewController: NSViewController, NSToolbarDelegate {
let toolbarItemIdentifier = NSToolbarItem.Identifier("group")
let toolbarItemIdentifierItem1 = NSToolbarItem.Identifier("item1")
let toolbarItemIdentifierItem2 = NSToolbarItem.Identifier("item2")
let toolbarItemIdentifierItem3 = NSToolbarItem.Identifier("item3")
override func viewDidAppear() {
let toolbar = NSToolbar()
toolbar.delegate = self
view.window!.toolbar = toolbar
view.window!.toolbarStyle = .expanded
}
func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.flexibleSpace, toolbarItemIdentifier]
}
func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
return [.flexibleSpace, toolbarItemIdentifier, .flexibleSpace]
}
func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
switch itemIdentifier {
case toolbarItemIdentifier:
let item1 = NSToolbarItem(itemIdentifier: toolbarItemIdentifierItem1)
item1.image = NSImage(named: NSImage.addTemplateName)!
item1.label = "add"
let item2 = NSToolbarItem(itemIdentifier: toolbarItemIdentifierItem2)
item2.image = NSImage(named: NSImage.homeTemplateName)!
item2.label = "home"
let item3 = NSToolbarItem(itemIdentifier: toolbarItemIdentifierItem3)
item3.image = NSImage(named: NSImage.pathTemplateName)!
item3.label = "path"
let group = NSToolbarItemGroup(itemIdentifier: itemIdentifier)
group.subitems = [item1, item2, item3]
group.selectionMode = .selectOne
group.selectedIndex = 0
group.target = self
group.action = #selector(selectItem(_:))
return group
default:
return nil
}
}
@objc func selectItem(_ sender: Any) {
print(0)
}
}
On iOS I can create a UIFont that automatically adapts to the font size chosen in the Settings app by the user:
label.font = UIFont.preferredFont(forTextStyle: .body)
label.adjustsFontForContentSizeCategory = true
(Copy-pasted from here.) I couldn't find a similar API for macOS. In the Accessibility settings I can change the font size and some apps react to it, like System Settings and Finder automatically increase the labels. Is there a way to create NSFont or NSTextField that automatically adapts to the chosen font size?
I've noticed that depending when I call NSApp.runModal(for:), the table view contained in the presented window is unresponsive: it either doesn't scroll at all, or the content only updates after one or two seconds, presumably after the inertial scrolling has ended.
In the sample code below I call NSApp.runModal(for:) in 3 different ways:
with a direct call
inside the callback to perform(_:with:afterDelay:)
inside the callback to DispatchQueue.main.async.
Only method 2 works. Why?
@main
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
// Insert code here to initialize your application
let window = NSWindow(contentViewController: ViewController(nibName: nil, bundle: nil))
// 1. doesn't work
runModal(for: window)
// 2. works
// perform(#selector(runModal), with: window, afterDelay: 0)
// 3. doesn't work
// DispatchQueue.main.async {
// self.runModal(for: window)
// }
}
@objc func runModal(for window: NSWindow) {
NSApp.runModal(for: window)
}
}
class ViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
override func loadView() {
let tableView = NSTableView()
tableView.addTableColumn(NSTableColumn())
tableView.dataSource = self
tableView.delegate = self
let scrollView = NSScrollView(frame: CGRect(x: 0, y: 0, width: 500, height: 500))
scrollView.documentView = tableView
view = scrollView
}
func numberOfRows(in tableView: NSTableView) -> Int {
return 100
}
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
return "\(row)"
}
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let cell = NSTableCellView()
cell.addSubview(NSTextField(labelWithString: "\(row)"))
return cell
}
}
I have a single-line label whose purpose is display file path, possibly very long.
Is there any way to shorten/compact the path string (with ellipse ...) so that the label still displays full path even it's too long?
Like below:
/some/very/long/path/to/some/filename.txt
to
/some/.../filename.txt
I am trying to add rows to GridView and not able to get expected row height correctly.
override func viewDidLoad() {
super.viewDidLoad()
// Remove the row in IB designer
gridView.removeRow(at: 0)
let image = NSImage(named: NSImage.colorPanelName)!
//image.size = NSMakeSize(80, 80)
let imageView = NSImageView(image: image)
imageView.imageFrameStyle = .grayBezel
imageView.imageScaling = .scaleAxesIndependently
imageView.frame = NSMakeRect(0, 0, 80, 80)
let label = NSTextField(labelWithString: "test text")
let row = gridView.addRow(with: [imageView, label])
row.height = 80
}
What was wrong with my code?
I have received a few crash reports for my app "Find Any File" with an assertion failure as follows:
assertion failure: "displayTiming != ((void *)0)" -> %lld
Googling this turns up nothing, though.
I wonder if someone has some insight into why this might happen, and how to prevent it.
One reporting user suggests that it happens when my app shows a very long list of items in an NSTableView (>10000 elements).
I have 4 reports from 3 users, and the main thread is doing something related to the table view each time, though not the same (the few other threads are all idle):
Crash 1, in macOS 14.0 (23A344:
Thread 0:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x182c69400 objc_msgSend + 0
1 AppKit 0x186f15400 -[CALayer(NSViewVisibleRect) NS_viewVisibleRectDidChange] + 40
2 AppKit 0x186900e10 NSViewHierarchyInvalidateVisibleRect + 276
3 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180
4 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180
5 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180
6 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180
7 AppKit 0x186900db0 NSViewHierarchyInvalidateVisibleRect + 180
8 AppKit 0x1869990e0 -[NSView translateOriginToPoint:] + 164
9 AppKit 0x186984108 -[NSClipView _immediateScrollToPoint:] + 420
10 AppKit 0x186983eb8 -[NSClipView scrollToPoint:] + 184
11 AppKit 0x186998d80 -[NSScrollView scrollClipView:toPoint:] + 84
12 AppKit 0x1869448dc -[NSClipView _scrollTo:animateScroll:flashScrollerKnobs:] + 480
13 AppKit 0x186b65b24 __62-[NSScrollingBehaviorConcurrentVBL _stopGestureScrollTracking]_block_invoke + 192
14 AppKit 0x186e6a6e8 ___NSMainRunLoopPerformBlockInModes_block_invoke + 44
15 CoreFoundation 0x18310b8c0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 28
Crash 2, in macOS 14.1.1 (23B81):
Thread 0:: Dispatch queue: com.apple.main-thread
0 CoreFoundation 0x18ba401f4 DYLD-STUB$$_Block_object_assign + 0
1 libsystem_blocks.dylib 0x18b506118 _call_copy_helpers_excp + 80
2 libsystem_blocks.dylib 0x18b505c68 _Block_copy + 376
3 libdispatch.dylib 0x18b641c7c _dispatch_Block_copy + 32
4 libdispatch.dylib 0x18b658df0 _dispatch_source_set_handler + 92
5 CoreFoundation 0x18b99e1e4 __CFRunLoopCopyMode + 540
6 CoreFoundation 0x18b8b7458 CFRunLoopAddObserver + 220
7 AppKit 0x18f0a687c _PerfAddRunLoopObserver + 192
8 AppKit 0x18f87cd60 -[NSApplication(NSEventRouting) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 368
9 AppKit 0x18f323318 -[_NSScrollingConcurrentEventMonitor startMonitoring] + 380
10 AppKit 0x18f321df8 -[NSScrollingBehaviorConcurrentVBL _scrollView:trackGestureScrollWithEvent:] + 884
11 AppKit 0x18f2e67f8 -[NSScrollingBehaviorConcurrentVBL scrollView:scrollWheelWithEvent:] + 512
12 AppKit 0x18f241770 forwardMethod + 252
13 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
14 AppKit 0x18f241770 forwardMethod + 252
15 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
16 AppKit 0x18f241770 forwardMethod + 252
17 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
18 AppKit 0x18f241770 forwardMethod + 252
19 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
20 AppKit 0x18fc45880 -[NSCollectionView scrollWheel:] + 180
21 AppKit 0x18f241770 forwardMethod + 252
22 AppKit 0x18f241770 forwardMethod + 252
23 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
24 AppKit 0x18f241770 forwardMethod + 252
25 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
26 AppKit 0x18f241770 forwardMethod + 252
27 AppKit 0x18f2e62a0 -[NSView scrollWheel:] + 408
28 AppKit 0x18f1d27b0 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 652
As you can see, there's no code of mine involved at the time of crash.
The other (and older) reports are similar, in macOS 13.6.1 and macOS 13.1. All four happened on ARM architecture (which may not be significant due to small number of samples). Memory use of app was not critical (in one case it was about 9 GB total, in others below 4 GB).
The "Binary Images" section only lists Apple libs, apart from my app's. So, there seems to be no 3rd party ext involved.
I've attached a full report as well.
Full report of Crash 1
I wanted to add some dock menu options for my application when it is not running. These dock menu options can be used to launch the application. I came across dock TilePlugin that can be used to add these dock options. But one of the comments in this forum discussion mentions that these Plugins are not allowed if you want ot publish your application in the appStore.
Can someone confirm this? If this is true, then Is there some other solution that can be used to add the dock options which appear when the application is not running, and can be used to launch the application?
Also do the recent open Files appear using this plugin mechanism?
The code below does not work properly in macos sonoma.
I tested it on multiple Macs (mini, m1, intel), but it does not work the same way.
(Normal operation in sonoma preview version and previous versions)
NSOpenPanel* openPanel = [NSOpenPanel openPanel]
Symptoms:
When you press the button, the cursor changes to a whirlwind icon.
My application and another system service (openAndSavePanelService) become "Not Responding".
However, after a few minutes, this condition is resolved and my application returns to normal, but openAndSavePanelService continues to be in the "Not Responding" state.
Suppose:
Looking at the attached spindump, it is assumed that when openPanel init is called, a problem occurs in the process of communicating with xpc and the system service (openAndSavePanelService) for displaying the dialog box.
What I tried:
Without creating an instance when pressing the button NSOpenPanel* g_openPanel = [NSOpenPanel openPanel] When the task is attempted in main and the button is pressed, openPanel was attempted with the created instnace, but failed.
Tried to work with NSOpenPanel* g_openPanel = [NSOpenPanel openPanel] via dispatch_async(dispatch_get_main_queue(), { ... }) but failed.
I found similar questions on forums but they didn't help.
https://developer.apple.com/forums/thread/104442?answerId=332068022#332068022
Project environment:
Cocoa project
Application is agent(UIElement)
Hardened Runtime (apple event checked)
No Sandbox
Network Extension
System Extension
Deployment Target: 10.9
Could it be a permission issue? Is there anything else worth trying?
This message is logged in Xcode when I start editing a text field in my macOS app.
This started appearing in Sonoma. This doesn't happen in Ventura (same Xcode project).
Every text field in the app is affected, regardless of the window.
What could be the cause of this?
If I use -[NSView dataWithPDFInsideRect:] to create a PDF from an NSTextView, I get a single-page PDF with stuff past the bottom cut off. What do I need to do to get pagination to happen? Would embedding the NSTextView in an NSScrollView help?
Hello,
I need to change the text of an NSScrollView at run time, but the command below is not working:
ScrViwRegras.documentView?.insertText (rules.retornaTextoRegras())
Where Rules is a struct that has the returnTextoRegras() method that returns the new text.
Has anyone had this problem?
Xcode 15.0.1 in MacBook Air not iOS), Swift 5,
Hugs
With my continued experiments with TextKit2, I'm trying to figure out what sets the properties paragraphSeparatorRange and paragraphContentRange on a NSTextParagraph. These seem to be computed properties (or at least they cannot be directly set via public API).
var paragraph = NSTextParagraph(attributedString: NSAttributedString(string: "It was the best of times.\n"))
print("attributes: \(paragraph.attributedString.attributes(at: 0, effectiveRange: nil))")
print("paragraphSeparatorRange: \(String(describing: paragraph.paragraphSeparatorRange))")
print("paragraphContentRange: \(String(describing: paragraph.paragraphContentRange))")
In the above example, both paragraphSeparatorRange and paragraphContentRange are nil.
However, when using NSTextLayoutManager/NSTextContentStorage they are set.
let layoutManager = NSTextLayoutManager()
let container = NSTextContainer(size: NSSize(width: 400, height: 400))
layoutManager.textContainer = container
let contentStorage = NSTextContentStorage()
contentStorage.textStorage = NSTextStorage(string: "It was the best of times.\n")
contentStorage.addTextLayoutManager(layoutManager)
layoutManager.enumerateTextLayoutFragments(from: contentStorage.documentRange.location, options: .ensuresLayout) { textLayoutFragment in
print("layoutFragment: \(textLayoutFragment)")
print("textElement: \(String(describing: textLayoutFragment.textElement))")
print("textElement.range: \(String(describing: textLayoutFragment.textElement?.elementRange))")
let paragraph = textLayoutFragment.textElement as! NSTextParagraph
print("paragraphContentRange: \(String(describing: paragraph.paragraphContentRange))")
print("paragraphSeparatorRange: \(String(describing: paragraph.paragraphSeparatorRange))")
return true
}
Would appreciate any ideas on how these values are computed/set. Thanks
I have an interesting challenge, but I do not know where to start.
given an NSTextView in an NSScrollView, and enough text in the textView to enable scrolling, how do you determine the location of a single word, and jump to it?
we see this sort of behavior in Find panels in Most text editors. So it can be done.
additionally, I would very much like to find some kind of predetermined... elements in the text. as a link or an image is not text but can be inline with the text (in Attributed strings) I would like to put an element in the text that is not text, but is targetable and capable of being tagged with some kind of reference. Almost like a bookmark, in which I can scroll to. I have determined that I could use URL Links. But they are so fragile.
I have a Mac doc based app.
I have save methods setup (they sort of work... I'm trying to get them up and running)
I'm using NSSecureCoding, with NSObjects in Swift. It has been unusually frustrating.
I have run into something I find wildly difficult to even explain.
I can save a new document that has not been saved yet. it loads as expected.
but if I make a change to a doc I have already saved, and save that, ny file gets wiped out. my save code is called, and the app wipes all of the data out of the saved file. The file exists, but it's emptied.
it goes from around ~200k in size to 2k in size.
there's no error that I have identified. It just wipes my file. So I have NO idea if it's something I did.
docs are... unhelpful. internet searches... are unhelpful.
this is just one of a number of errors I have to figure out, but it is massively complicating everything else.
any ideas welcome.
Hello,
Is it possible fill NSpastebard with public.file-url which will initially point the an empty file.
And when Finder will paste the file, my Application will download it and Finder will wait for the completion of the download.
My goal is not to use drag & drop.
I saw that Microsoft RDP client is doing file download using this way. But I don't know how it works. Empty file is created in sandbox.
I have had this issue for a long time. If I configure any auto layout constraints in TableViewCell, I get extremely weird layout behavior in IB designer; however, layout is completely good during runtime.
For example, with a completely new project and a single NSTableView on the main view, I get:
If I resize main view, the tableview won't get resized
Every time I reopen the project, the tableview would shrink by height.
It seems the shrinked height is doubled every time. For example, in the following screenshot, the gap is 56. Next reopen will double the gap to 112.
Is this a known bug? I would want to file bug report at https://feedbackassistant.apple.com.
Hello,
here is the block where arrayController is nil :
{
NSData * data;
NSError * error;
Class klass;
if(_arrayController != nil) // nil !
{
selected = [_arrayController selectedObjects];
arranged = [_arrayController arrangedObjects];
if([selected count] > 0)
{
_currentObject = [selected objectAtIndex:0];
if(_currentObject != nil)
{
data = [_currentObject valueForKey:kVrRoot];
klass = [NSMutableDictionary class];
_vrRoot =
[NSKeyedUnarchiver unarchivedObjectOfClass:klass fromData:data error:&error];
}else
{
_vrRoot = [NSMutableDictionary new];
data = [NSKeyedArchiver archivedDataWithRootObject:_vrRoot requiringSecureCoding:YES error:&error];
}
}
}
}
I use this for years so I don't no what's wrong.
I have an Objective-C App that has worked perfectly until Monterey was released. The app is activated and displays a window when it’s hotkey is typed. The problem is that—starting in Monterey—if the cursor is in an html Password field of ANY website in ANY browser, the app’s window does not display. After many many hours of debugging, I have determined that the problem is that in this case, [NSApp activateIgnoringOtherApps:YES] never activates the app, and that [myWindow makeKeyAndOrderFront:nil] does nothing. In this case, if I display a window using [NSApp runModalForWindow:myWindow], the window does display, but is not key until it is clicked, at which point the app activates.
Note that everything works properly with the cursor in any browser field other than a Password field, or in any other app. It also works with the cursor anywhere in MacOS versions 10.12 through 11.
Is this is some kind of new security feature? Is this a bug or is there a workaround for this? I there a low-level non-Cocoa way to activate an app?
I allow users to choose a font to use throughout the app, then display text using that font in 3 different ways:
As the default body font of an HTML document displayed in a WKWebView.
Used to create an NSAttributedString then displayed in an NSTextField.
Used as the body font of a very small HTML document (2-3 lines), converted to NSAttributedString, then displayed in an NSTextField.
My code has been working fine for years, but starting with the release of Sonoma (macOS 14), any text that is converted from HTML to NSAttributedString displays as all "question marks in boxes" for each character. This happens when certain fonts are used. In particular I've seen it with Calibri, Candara, and SF Pro. Calibri and Candara are Microsoft fonts and I think are distributed with MS Office. SF Pro is an Apple font.
There could be others; I haven't done an exhaustive check. What I can tell you is that this has been working fine literally until a couple weeks ago when customers began installing macOS 14. If they go into my app and select a different font (such as Arial or Times New Roman) everything works fine. It is only certain fonts that don't work, and those fonts work when used as the body font of an HTML document in WKWebView and when used as the font for a new NSAttributedString. They just don't work if you make a little HTML document with the font selected as the body font, then convert to NSAttributedString.
Here's the code that worked up until macOS 14:
NSString *htmlString = @"<!DOCTYPE html>"
"<html>"
"<head>"
"<style>"
"body { font-family: 'Candara', serif; font-size: 14px; }"
"</style>"
"</head>"
"<body>"
"This won't display right."
"</body>"
"</html>";
NSData *htmlData = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)};
NSError *error;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:htmlData
options:options
documentAttributes:nil
error:&error];
Note the fallback of "serif" — that doesn't matter. you get all undefined characters and the fallback font is not used. It's as if the renderer really believes the font is usable, but it isn't.