Custom View in Scroll View scrolls to bottom by default.

I originally posted this same question in the ASS side of things ( - sorry for the double post :rolleyes: ) I believe that it also applies to AppleScriptObjectiveC because the issue may deal with interface builder, and might not be specific to AppleScriptStudio or AppleScriptObjC. So, here goes:

I have a “custom view” in a “scroll view” in interface builder. When I build the app, by default, the scroll view scrolls to the bottom. I’d like for the scroll view to be scrolled to the top. Also, I notice that the coordinates are “upside down” Using Interface builder 3.2.5 (823) XCode Version 3.2.5 on an applescript studio app.

Here is what I have tried:

  1. Adjusting every setting I can find in interface builder to try and prevent this. Maybe there is a simple setting in IB that I have missed?

  2. I have tried to find applescript code to “scroll” to the top once the app launches:

call method "scrollCellToVisibleAtRow:column:" of (matrix "studentfiles" of view "studentsfiles" of scroll view "studentsfiles" of window "studentsfiles") with parameters {theRow, theColumn}

This app is in Applescript Studio, but I might need to insert some ObjectiveC (I don’t quite know how to do this, but I’d be eager to learn).

If anyone can help, a big thanks!

I don’t know if there’s a way to do that in IB, but the following code worked for me:

on applicationWillFinishLaunching_(aNotification)
		set viewHeight to custView's frame()'s |size|()'s height()
		set clipViewHeight to custView's superview()'s frame()'s |size|()'s height()
		custView's scrollPoint_({x:0, y:viewHeight - clipViewHeight})
	end applicationWillFinishLaunching_

custView is the outlet for the custom view that’s in the scroll view.


Ric -

Thank you for your reply. This will definitely be useful to anyone using ASOC!

set x to 0
set y to calculatedHeightOfYourNSView -- Calculate the height of your NS view, or use a fixed value
call method "scrollPoint:" of object (view 1 of scroll view 1 of window 1) with parameter {x, y}

Above, I have re-written this for ASS, and will post this info in my other post as well. The trick was:
For NSView, use “scrollPoint” (thanks, Ric, that was the key). All of the other posts I had been looking at were for NSTextView, which is why “scrollRangeToVisible” and “scrollCellToVisibleAtRow” was not working!

Thanks again, Ric!