nsview

Custom NSView embedded in NSSscrollView

不问归期 提交于 2020-01-05 09:11:43
问题 Is there a way for a custom NSView to know whether it is embedded in a NSScrollView or not? I am creating a custom NSView for displaying some content. When my view is placed in a window or another view, its size is fixed and the content is clipped to available size. When my view is placed in a NSScrollView its size must be adjusted according to content so it can be scrolled if necessary. I know I can add a member in my view that specifies the NSScrollView that hosts my view and set this

Resize view of NSCollectionViewItem

早过忘川 提交于 2020-01-04 09:16:50
问题 How do I programatically set the size of a view of an NSCollectionViewItem? I tried doing this in an NSCollectionView subclass: @implementation CustomCollectionView - (NSCollectionViewItem *)newItemForRepresentedObject:(id)object { NSCollectionViewItem *newitem = [[self itemPrototype] copy]; [newitem setRepresentedObject:object]; NSView *itemview = [newitem view]; [itemView setFrame:NSMakeRect([itemView frame].origin.x, [itemView frame].origin.y, [itemView frame].size.width, 500)]; return

mouse click events in an NSView subclass

亡梦爱人 提交于 2020-01-04 05:38:08
问题 I have an NSView subclass that gets initialized with an OpenGL context and has a bunch of mouse event handling (onMouseDown, etc...). I have an app using it which has a main Cocoa window that contains the view and all the mouse events are working properly. However, I'm trying to use it now in another app where i have a secondary window that pops open and gets initialized with the view and while i get mouse moved evets, I don't seem to get any mouse click (or keyboard for that matter) events

How can I darken everything displayed in a single NSView?

时间秒杀一切 提交于 2020-01-04 02:33:09
问题 Background: My application has a main window which contains a few smaller NSView objects, each of which contains several different controls, labels, images, etc. One of these views (and everything it contains) is disabled in response to a given flag. When the flag is set, I automatically disable and grey-out all of the controls embedded within that NSView . Question: I would like to know how to darken the disabled NSView . The effect I am looking for would be something like drawing a 50%

NSView does not receive mouseUp: event when mouse button is released outside of view

a 夏天 提交于 2020-01-03 18:43:06
问题 I have a custom NSView subclass with (for example) the following methods: override func mouseDown(with event: NSEvent) { Swift.print("mouseDown") } override func mouseDragged(with event: NSEvent) { Swift.print("mouseDragged") } override func mouseUp(with event: NSEvent) { Swift.print("mouseUp") } As long as the mouse (button) is pressed, dragged and released all inside the view, this works fine. However, when the mouse is depressed inside the view, moved outside the view, and only then

NSView does not receive mouseUp: event when mouse button is released outside of view

一世执手 提交于 2020-01-03 18:43:01
问题 I have a custom NSView subclass with (for example) the following methods: override func mouseDown(with event: NSEvent) { Swift.print("mouseDown") } override func mouseDragged(with event: NSEvent) { Swift.print("mouseDragged") } override func mouseUp(with event: NSEvent) { Swift.print("mouseUp") } As long as the mouse (button) is pressed, dragged and released all inside the view, this works fine. However, when the mouse is depressed inside the view, moved outside the view, and only then

Subclassing NSScrollView drawRect: Method

六眼飞鱼酱① 提交于 2020-01-02 05:23:16
问题 I'm customizing the UI for one of my apps, and the idea is that a text area is initially bordered gray when out of focus, and when it comes into focus, the border becomes bright white. My app uses a dark theme, and for a single-lined NSTextField , this works great. I'm running into problems with a subclassed NSTextView , however. In order to alter the border properly, I ended up having to actually subclass the parent NSScrollView , but am still seeing strange behavior. (See screenshot below.)

Swift 3 Load xib. NSBundle.mainBundle().loadNibNamed return Bool

北城以北 提交于 2020-01-02 02:28:06
问题 I was trying to figure out how to create a custom view using xib files. In this question the next method is used. NSBundle.mainBundle().loadNibNamed("CardView", owner: nil, options: nil)[0] as! UIView Cocoa has the same method,however, this method has changed in swift 3 to loadNibNamed(_:owner:topLevelObjects:), which returns Bool , and previous code generates "Type Bool has no subscript members" error, which is obvious, since the return type is Bool. So, my question is how to a load view

Core Animation - Sheet-like Window Sliding

孤人 提交于 2020-01-01 18:12:42
问题 How difficult would it be to use core animation to make an NSView slide in an out of view like a sheet? Generally speaking, what would be involved in accomplishing this? I've been reading through the CA documentation, but it's been hard for me to pinpoint which parts are relevant to what I want to do since I have no experience with the framework. Any tips at all would be much appreciated. Thanks. 回答1: Since you're talking of a NSView, you're probably using Cocoa's animation support, not CA

The Autosizing property setting for NSView is missing

久未见 提交于 2020-01-01 10:54:05
问题 I ran into this really frustrating issue today. I want to set my view to be autosizing like this: But all I find in my xcode settings for an NSView is like this: The two screenshots are taken from two different projects with the same xcode 4.3.2. Is this a bug or am I missing something? Thanks. 回答1: Seaid's solution works. but i think it's bug because the auto sizing tool will apear about half a second when switching to another inspector. Xcode 4 interface-builder problems 回答2: Starting in