3

让我直截了当,

有 3 个像附件一样的滚动视图,我对代表感到困惑。见链接: 图片截图

这里是 :

  1. 滚动 1 - 仅垂直滚动
  2. scroll 2 - 可以自由滚动(水平/垂直)
  3. 滚动 3 - 仅水平滚动

如果我水平滚动“滚动 2” ,我想制作,那么“滚动 1”也是滚动的。如果我垂直滚动“滚动 2”,那么“滚动 3”也是滚动的。

如果有关于此的示例代码/示例,那就太好了。

问候,

天空。

4

1 回答 1

2

我做了类似于两个 NSTableViews 的事情,滚动一个会产生第二个滚动。

这是代码:

MyScrollView.h

#import <AppKit/AppKit.h>
#import "AppDelegate.h"

@interface MyScrollView : NSScrollView

@property (strong) AppDelegate *app;

@end

MyScrollView.m

#import "MyScrollView.h"
//#define LogRect(RECT) NSLog(@"%s: (%0.0f, %0.0f) %0.0f x %0.0f", #RECT, RECT.origin.x, RECT.origin.y, RECT.size.width, RECT.size.height)

@implementation MyScrollView
@synthesize app;

- (void)reflectScrolledClipView:(NSClipView *)aClipView{
     [super reflectScrolledClipView:(NSClipView *)aClipView];


    //post a notification
    app=[[AppDelegate alloc] init];

    if (app) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"scrolled" object:aClipView];
    }

}    
@end

AppDelegate.h

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

@property (strong) IBOutlet NSTableView *aTableView;
@property (strong) IBOutlet NSTableView *bTableView;
@property (strong) IBOutlet NSTableView *cTableView;

@property (strong) IBOutlet NSView *aView;
@property (strong) IBOutlet NSView *bView;

@end

AppDelegate.m

#import "AppDelegate.h"

@implementation AppDelegate

/*
 Unwanted methods are not shown here, like delegates, datasource, init etc
*/

-(void)scrollTable:(NSNotification *)aNotification{
    NSPoint globalLocation = [NSEvent mouseLocation ];
    NSPoint windowLocationForA = [[aView window ] convertScreenToBase:globalLocation ];
    NSPoint viewLocationForA = [aView convertPoint: windowLocationForA fromView: nil ];
    NSPoint windowLocationForB = [[bView window ] convertScreenToBase:globalLocation ];
    NSPoint viewLocationForB = [bView convertPoint: windowLocationForB fromView: nil ];

    if (NSPointInRect(viewLocationForA, [aView bounds])) { // i scrolled on A
        NSLog(@"Scrolled A");
        if ([[[aTableView superview]superview] isEqualTo:[[aNotification object] superview]]) {
            [bTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]];
            [cTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]];
        }
    }
    else if (NSPointInRect(viewLocationForB, [bView bounds])) { // i scrolled on B
        NSLog(@"Scrolled B");
        if ([[[bTableView superview]superview] isEqualTo:[[aNotification object] superview]]){
            [aTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]];
            [cTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]];
        }
    }
    else{ // i scrolled on C
        NSLog(@"Scrolled C");
        if ([[[cTableView superview]superview] isEqualTo:[[aNotification object] superview]]){
            [aTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]];
            [bTableView scrollRectToVisible:[[aNotification object] documentVisibleRect]];
        }
    }
}


-(void)awakeFromNib{

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(scrollTable:)
                                                 name:@"scrolled"
                                               object:nil];

}

@end
于 2013-02-26T04:56:58.933 回答