作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将 Cappuccino 0.9.6 与 XcodeCapp 一起使用。我有一个 CPCollectionView 填充了 CPImageView 子类型项 (ThumbnailView)。现在我希望这些项目是可拖动的。
我修改了 Scrapbook #2 - Drag and Drop 中的说明以我的 xcode 界面为例(尚未实现拖动目标),但是,这些项目不可选择,更不用说可拖动了。关于出了什么问题的任何想法?
应用 Controller .j
@import <Foundation/CPObject.j>
@import "MediaController.j"
@implementation AppController : CPObject
{
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
@outlet MediaController mediaController; // connected to AppController
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
// load media
[mediaController loadMedia];
}
- (void)awakeFromCib
{
[theWindow setFullPlatformWindow:YES];
}
@end
ThumbnailDragType = @"ThumbnailDragType";
@implementation MediaController : CPObject
{
CPArray images;
// outlets
@outlet CPCollectionView thumbnailCollectionView; // connected to CPCollectionView in interface builder
}
- (id)loadMedia
{
[thumbnailCollectionView setAutoresizingMask:CPViewWidthSizable];
[thumbnailCollectionView setMinItemSize:CGSizeMake(150, 150)];
[thumbnailCollectionView setMaxItemSize:CGSizeMake(150, 150)];
[thumbnailCollectionView setDelegate:self];
var itemPrototype = [[CPCollectionViewItem alloc] init];
[itemPrototype setView:[[ThumbnailView alloc] initWithFrame:CGRectMakeZero()]];
[thumbnailCollectionView setItemPrototype:itemPrototype];
image1 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample.jpg" size:CGSizeMake(500.0, 430.0)];
[image1 setName:'bla'];
image2 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample2.jpg" size:CGSizeMake(500.0, 389.0)];
[image2 setName:'asdfsadfdf'];
image3 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample3.jpg" size:CGSizeMake(413.0, 400.0)];
[image3 setName:'asdfadsggewa'];
image4 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample4.jpg" size:CGSizeMake(500.0, 375.0)];
[image4 setName:'aisdfiojf'];
image5 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample5.jpg" size:CGSizeMake(500.0, 375.0)];
[image5 setName:'oiajdf'];
image6 = [[CPImage alloc] initWithContentsOfFile:@"Resources/sample6.jpg" size:CGSizeMake(500.0, 375.0)];
[image6 setName:'aidsoifsd'];
images = [image1, image2, image3, image4, image5, image6];
[thumbnailCollectionView setContent:images];
return self;
}
- (CPData)collectionView:(CPCollectionView)aCollectionView dataForItemsAtIndexes:(CPIndexSet)indices forType:(CPString)aType
{
return [CPKeyedArchiver archivedDataWithRootObject:[images objectAtIndex:[indices firstIndex]]];
}
- (CPArray)collectionView:(CPCollectionView)aCollectionView dragTypesForItemsAtIndexes:(CPIndexSet)indices
{
return [ThumbnailDragType];
}
@end
@implementation ThumbnailView : CPImageView
{
CPImageView imageView;
CPView labelView;
CPTextField label;
}
- (void)setSelected:(BOOL)isSelected
{
[self setBackgroundColor:isSelected ? [CPColor grayColor] : nil];
}
- (void)setRepresentedObject:(id)anObject
{
if (!imageView)
{
var frame = CGRectInset([self bounds], 5.0, 5.0);
// make imageView
imageView = [[CPImageView alloc] initWithFrame:frame];
[imageView setImageScaling:CPScaleProportionally];
[imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[self addSubview:imageView];
// make label view
labelView = [[CPView alloc] initWithFrame:CGRectMake(
5.0,
125.0,
140.0,
20.0
)];
[labelView setBackgroundColor:[CPColor blackColor]];
// make label
label = [[CPTextField alloc] initWithFrame:CGRectInset([labelView bounds], 3.0, 3.0)];
[label setTextColor:[CPColor whiteColor]];
[labelView addSubview:label];
[self addSubview:labelView];
}
[imageView setImage:anObject];
[label setStringValue:[anObject name]];
}
@end
最佳答案
在 Xcode 中,确保 Collection View 被标记为“可选”(见附图)。
关于cappuccino - 使用界面生成器从 CPCollectionView 拖放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19362551/
我将 Cappuccino 0.9.6 与 XcodeCapp 一起使用。我有一个 CPCollectionView 填充了 CPImageView 子类型项 (ThumbnailView)。现在我希
我是一名优秀的程序员,十分优秀!