Friday 15 April 2011

osx - Subview of subclassed NSView re-positioned incorrectly after drawing a focus ring -


I wanted to create a focus ring outside a subclass NSV to identify the selection. My reference comes from here.

I followed the reference, overwritten the -drawRect method:

  @property (nonatomic) should be DisplayFocus; ... - (Zero) Draw Draw: (NSRact) dirty underlined {// drawing code here. If (_Should Display Focus) {[Self-Setting KeyboardFocusingNewsDisplaylineRectects: [Self limit]]; } [Super drawRect: Gandharct]; [[Enkolor black color] set]; NSRectFill (dirtyRect); If (_blood displayfox) {nsatfocceringstyle (NSFocSringTypeextare); NSBezierPath * path = [NSBezierPath bezierPathWithRect: NSInsetRect ([self limit], -1.0, -1.0]]; [[Enkolor black color] set]; [Path stroke]; [NSGraphicsContext ReplaceGraphicsState]; }}   

and its -musdown: method is overwritten:

  - (zero) mouse mode: (NSEvent *) TheEvent {[Super MouseDown: Avent]; If (_delegate & amp; amp; [_delegate responds]] Tselector: @sillector (mouseDownAview: Atvant :)) [[DDEEGET MauiDownOutview: Documents with Self: Avent]; }}   

After clicking more views, its representative will set / unset the Focus Ring and who will call it back to -drawRect: .




It did the job and see the focus ring correctly generated out. However, a problem came soon:

I had an image view inside the subclassed scene. As the image view rectangle had an automatic layout with NSLayoutConstraint objects, I make four NSLayout contract outlets to adjust my values. I do not often change the layout restrictions in fact, as the image's size is unchanged, I will not set them.

Here is a situation when the subclassed view was not clicked (looked OK):

Then click on the image (focus bell But .. ..):

And I tried to change the size of the window, things are even more sad "funny":

I could not understand why the problem is or how to solve it. Can anyone help me with that? I uploaded my sample code here:


It is very sad that no one answers the question.

I found that the subpages also incorrectly layout when they add to this view by the -addSubview: and -setFrame method. [NSGraphicsContext saveGraphicsState]

(_shouldDisplayFocus) { block.

You call [NSGraphicsContext reproductionGraphicsState] to call the graphics position on the stack, but you never put anything on the heap to attract cocoa everything. Graphics is using state stack so that you are popping up some unknown situation, which has something to do with the status of the image. If you want to add a focus ring style and be able to remove the focus ring style, then you first need to save the graphic position, set the focus ring style to whatever you want, and then the graphics Restore which it was. / P>

No comments:

Post a Comment