• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSView + NSScrollView, not scrolling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSView + NSScrollView, not scrolling


  • Subject: Re: NSView + NSScrollView, not scrolling
  • From: Andy Lee <email@hidden>
  • Date: Tue, 08 May 2012 14:56:54 -0400

On May 5, 2012, at 3:31 AM, qvacua wrote:
> - (void)keyDown:(NSEvent *)theEvent {
>    unichar key = [[theEvent characters] characterAtIndex:0];
>    NSLog(@"\\U%X pressed", (int)key);
>
>    [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
> }
>
> - (BOOL)acceptsFirstResponder {
>    return YES;
> }
> @end
>
> In "applicationDidFinishLaunching:" I set the frame size of the view
> to something big using setFrameSize.
>
> What I want — but now working — is scrolling via Page Up/Down key. If
> I understand the doc correctly, I just have to call
> "interpretKeyEvents:" like above

Remove your override of keyDown: and the scrolling should just work. At least it does in a test I just did. I'm a little puzzled since I assume your code comes from this example in the docs:

<https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html#//apple_ref/doc/uid/10000060i-CH7-SW13>

In my test I was surprised to find that the view's doCommandBySelector: doesn't get called. Either something's changed or there's something I misunderstood. I don't see how the key events get mapped to the page-scrolling methods without a call to doCommandBySelector:, which I thought did that mapping.

Here are all the methods I implemented in my view class. Feel free to use the drawing code so that you can see the scrolling more vividly.

- (void)drawRect:(NSRect)dirtyRect
{
    NSRect boxRect = NSMakeRect(0, 0, 200, 30);

    for (NSInteger boxIndex = 0; boxIndex < 100; boxIndex++, boxRect.origin.y += 30)
    {
        // Draw colored background.
        if (boxIndex & 1)
        {
            [[NSColor yellowColor] set];
        }
        else
        {
            [[NSColor orangeColor] set];
        }
        NSRectFill(boxRect);

        // Draw box number.
        NSString *s = [NSString stringWithFormat:@"%ld", boxIndex + 1];
        [s drawInRect:boxRect withAttributes:nil];
    }
}

- (BOOL)isFlipped
{
    return YES;
}

- (BOOL)acceptsFirstResponder
{
    return YES;
}

- (void)doCommandBySelector:(SEL)aSelector
{
    NSLog(@"<%@: %p> -- %s -- will try to do command %@", [self className], self, __PRETTY_FUNCTION__, NSStringFromSelector(aSelector));
    [super doCommandBySelector:aSelector];
}

--Andy


_______________________________________________

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


References: 
 >NSView + NSScrollView, not scrolling (From: qvacua <email@hidden>)

  • Prev by Date: Re: Issue when hiding NSTableColumn while resizing
  • Next by Date: Re: self.myTextField.stringValue = @"" fails
  • Previous by thread: Re: NSView + NSScrollView, not scrolling
  • Next by thread: -[NSApp orderOut:] leaves custom sheet in -orderedWindows
  • Index(es):
    • Date
    • Thread