Re: Scroll view within scroll view blocks scrolling
Re: Scroll view within scroll view blocks scrolling
- Subject: Re: Scroll view within scroll view blocks scrolling
- From: Philip Dow <email@hidden>
- Date: Sat, 14 May 2011 11:19:32 -0500
On May 14, 2011, at 1:35 AM, William Squires wrote:
>
> On Apr 28, 2011, at 6:12 PM, Indragie Karunaratne wrote:
>
>> Despite the confusing title, I'm sure this is an issue that someone else has run into before. I have a parent scroll view that houses a bunch of subviews, including an NSTextView (and its own scroll view). The problem is that if I try to scroll vertically through the parent view, the text view's scroll view "blocks" my scrolling if I try to scroll while the cursor is within the text view. How can this be avoided?
>
> It can't - all Mac programs do this - try loading a web page in Safari that has a sub-block of text in the main page (that's too tall to display in the parent window, thus requiring a scroller. You just have to watch out where you put your cursor! :) I run across this often while researching on wikipedia.org!
>
It can, although you may end up creating additional problems for yourself which you'll need to work around.
You need a custom subview, probably whatever you're setting as the document view in your main scroll view. You can override the NSView hitTest: method so that it returns self whenever the point falls in one of the enclosed scroll views. This will cause all mouse events to be ignored by those sub scroll views, including scroll events.
Make sure you read up on this hitTest: method first. Overriding it incorrectly can seriously screw up your UI.
The problem: well, mouse events are also ignored in the enclosed text views, so that you can no longer select the text or click on links within that text without additional logic. If that isn't an issue, all the better.
Another solution, if it's an option, is to size the enclosed text views so that they always perfectly fit their content, which would let you disable all those lower level scroll views so that you don't run into this problem at all. The wonderfully complex NSLayoutManager provides the methods you need to determine how heigh a text storage needs to be to accommodate all its text, given a certain width. Have a look at usedRectForTextContainer:
~Phil
http://getsprouted.com
>>
>> Thanks,
>> Indragie_______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden