Cut*_*are 1 macos cocoa objective-c appkit nsscrollview
我有一个NSScrollView,其documentView是一个巨大的NSView,由许多子NSImageViews组成,他们在地图中充当瓷砖.(整个地图是NSView,因为它比屏幕大小大,所以它嵌入在滚动视图中).
我能够使用正确的平铺位置显示地图,并使用条形/手势滚动.但是..当我启用放大倍率才能进行缩放时,会发生以下情况:
不知怎的,我假设自动布局添加下面的瓷砖边框,我不知道如何禁用它们.这些肯定是边界,因为我已经检查了数千次我的瓷砖和子视图大小相同..所以它来自哪里?我对iOS开发有很多经验,但是我完全迷失了NSScrollView(我的委托方法在哪里?).如何禁用滚动视图的此行为?
这是我的子视图代码:
- (void)setupSubViews
{
NSLog(@"--------Creating subviews!-------");
//first we create the subviews..
//This is the key part, we traverse from top Left, and since OS X coordinates start at bottom left, we need to invert the rows!
for (int i=0; i< NUMBER_OF_COLUMNS; i++) {
for (int j=NUMBER_OF_ROWS-1; j>=0; j--) {
CGRect frame = CGRectMake(i*256, j*256, 256, 256);
NSImageView *newView = [[NSImageView alloc] initWithFrame:frame];
newView.focusRingType = NSFocusRingTypeNone; //I gave this focusRing a try, it didn't work :(
[self addSubview:newView];
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我将子视图连接到实际图像的地方..
-(void)updateMap:(id)tilesPassed{
if (downloadFinished) {
NSLog(@"--------DRAW RECT-------------");
NSImageView *subView;
NSInteger idx = 0;
for (int i =0; i<[self.subviews count]; i++) {
subView = [self.subviews objectAtIndex:i];
[subView setAllowsCutCopyPaste:NO];
[subView setImageFrameStyle:NSImageFrameNone]; //This doesnt work either :(
MapTile *tile = [tilesArray objectAtIndex:idx];
subView.image = tile.image;
idx++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
您可能不想为此使用子视图.CALayer确切地说,有一个子类CATiledLayer:https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CATiledLayer_class/Introduction/Introduction.html
有了它,您甚至可以根据放大的距离加载不同的图像切片,就像谷歌地图一样.它将呈现无边框,性能将比使用大量子视图更好.子视图很昂贵,层(通常)便宜.
更新:此示例将帮助您启动并运行:http://bill.dudney.net/roller/objc/entry/catiledlayer_example
| 归档时间: |
|
| 查看次数: |
1211 次 |
| 最近记录: |