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 protected])
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]