Please see attached image: http://i45.tinypic.com/fu8bpz.png
Has anyone every seen this kind of weird scroll bar behavior? I embedded a custom view in an NSScrollView. The scroll bars do not appear to be drawing correctly, and they also appear in the middle of my custom view. This happens on 10.6, yet not when I build on 10.7. I also see it on 10.8. I have tried fixing this by building in XCode 3.2 as well as XCode 4.3.
I was not balancing my [[NSGraphicsContext current] saveGraphicsState] with the appropriate [[NSGraphicsContext current] restoreGraphicsState]. Each [[NSGraphicsContext current] saveGraphicsState] must be balanced with a [… restoreGraphicsState] call, otherwise the GraphicsContext will be in an unpredictable state.
Related
Anyone having problems with your Custom NSView's inside a NSScrollView? I have a NSScrollView with a custom NSView that uses its draw(rect:) function to do all the work.
Before OSX 10.14, each time scrollview was marked with setNeedsDisplay, the documentView would also refresh. On OSX 10.14 I need to specifically mark the doucmentView to setNeedsDisplay too. Looks like its ignoring the NSScrollView.contentView.copiesOnScroll property.
Does anyone have similar issues or point me to release notes? the NSAppKit release notes don't say anything about NSScrollView.
We encountered the same problem. After several days of experimenting, the cause for the problem in our setup was as follows:
The documents we need to draw can be quite large. Therefore we optimised drawing in NSView's drawRect method to paint the visible portions of the document only, according to the clip-rectangle:
NSRect clipRect = [nsClipView bounds];
This worked great before Mojave.
Under Mojave our code would display black for the portions of the document that scrolled into the visible region.
We changed our drawing routines to display exactly the areas indicated by the 'dirty rectangle' of the drawRect method:
- (void)drawRect:(NSRect)dirtyRect
Now scrolling works under Mojave.
I am attempting to change the coordinates of an NSButton that is contained within a parent NSView and something is clearly not working, because the button position does not change. Both elements are defined in a nib file and the parent view has animation applied to it using CoreAnimation.
I have tried the following.
button.frame.origin.x = 500
and...
var frame:CGRect = button.frame
frame.origin.x = 500
button.frame = frame
Even with the animations disabled, I can not seem to dynamically position the subview. Is there some feature that prevents children views from being positioned programmatically?
Please note that I am using Swift with XCode 6.3.1.
I'm guessing you're using AutoLayout constraints, given you're using the latest tools.
If so, setting a subview's frame directly won't work the way you're expecting (if it does anything at all, it'll cause strange drawing glitches / flashing when mixed with animation). You have to create outlets for your layout constraints and modify them.
If you're not using AutoLayout, I suggest having a look at your button outlet to make sure it's actually connected (ie, you're not talking to nil). Even if the outlet is connected, make sure it's not nil at runtime - you may be trying to talk to the button before the nib is loaded and the outlet / action connections are restored.
I'm using a view based NSTableView which displays a NSTableRowView containing an NSImageView and some NSTextFields. The NSTextFields are having the backgroundColor property set and are drawing correctly. I've tried to draw them with rounded corners by setting
[textfield.layer setWantsLayer: YES];
[textfield.layer setCornerRadius: 5.];
What is working but causes the views with the applied corner radius to flicker while scrolling the table view. Setting the view's layer via textfield.layer [setLayer: [CALayer layer]] or forcing the layer to rasterize by setting [textfield.layer setShouldRasterize: YES] also did not work. Any suggestions how to get rid of the nasty flickering?
I'm developing on Mavericks for Mavericks using Xcode 5.
With the help of uchuugaka's post I was able to fix it using this tutorial: Tutorial
I have a 10.7 app built on 10.9. I'm debugging on 10.9.
My main view has a splitView with two panes: a webview in one, and an NSScrollView in the other.
When the app starts I programmatically move the divider to the right to hide the right-hand pane and the enclosed NSScrollView.
When this happens I get this warning in the console:
Layout still needs update after calling -[NSScrollView layout].
NSScrollView or one of its superclasses may have overridden -layout
without calling super. Or, something may have dirtied layout in the
middle of updating it. Both are programming errors in Cocoa
Autolayout. The former is pretty likely to arise if some pre-Cocoa
Autolayout class had a method called layout, but it should be fixed.
This only happens when the view is first loaded when the app starts. Switching away to a new view, and back, is fine.
I think the problem is that the scroll view is still being drawn when I move the splitView divider, causing the scrollview to be dirtied.
If I comment out the line that moves the divider I do not see the message.
FYI, I did not get the error when building / debugging on 10.8.
From Googling around the consensus seems to be that this is a bug in 10.9 and can be ignored, but I don't like to leave my code with warnings.
Does anyone know how I can fix this? I need to move the code that moves the divider to a point AFTER the view has been fully drawn.
Thanks
Darren.
I'm placing a few buttons in a simple rectangular NSview which acts as a custom toolbar. On first render the buttons/views come out as expected, but every time a button is pressed (and sometimes with no mouse interaction at all) artefacts start appearing.
Before
After
I can eliminate the artefacts by calling a [self.toolbarView setNeedsDisplay:YES] in all the action and focus methods but this seems like a hack, is there any clean way to deal with this?
It was a beginner's problem. In the drawRect method
- (void)drawRect:(NSRect)dirtyRect
I was using the param dirtyRect for drawing an outline of my view, assuming it was the view's bounds, where in fact it was only the area around the buttons that became dirty when they were pressed. The 'artefacts' were actually my outline being drawn in the wrong place.
By correctly using the bounds of the view
NSRect drawingRect = [self bounds];
the 'artefacts' no longer appeared.
You just try to set focus ring for a buttons to 'none' in IB.