swiftcocoansimageview

Determine if NSImageView is highlighted


I have a view with multiple NSImageViews. How can I determine which NSImageView is highlighted when selected by the user? The isHighlighted property is always the same.


Solution

  • To determine if any view has focus, you check if it is its window's firstResponder:

    if (someView.window.firstResponder == someView)
        ...
    

    There's a complication with text fields, because they use another object as a field editor, but that's not relevant for image views.