1
我有一个奇怪的问题,在Mac上的一个简单的NSScrollView。我刚开始在Cocoa编程,但我以前在iOS上使用过UIKit。我在我的xib文件中添加了一个NSScrollView,并将我在窗口中放置滚动视图时由Xcode自动生成的NSView划分为子类。子类只是将内容视图添加到滚动视图并绘制背景。那就是:NSScrollView没有响应手势
#import "TweetsView.h"
@implementation TweetsView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)awakeFromNib {
[self reload];
}
- (void)reload {
//Retrieve tweets
ACAccount *account = [[TwitterModel retrieveTwitterAccounts] objectAtIndex:1];
TwitterModel *model = [[TwitterModel alloc] init];
NSArray *timeline = [model retrieveMainTimelineWithAccount:account];
//Display the tweets
int stackHeight = 0;
for (NSDictionary *tweetDictionary in timeline) {
TweetView *tweetView = [[TweetView alloc] initWithFrame:NSMakeRect(0, stackHeight, self.frame.size.width, 60)];
[tweetView setMainText:[tweetDictionary objectForKey:@"text"]];
[self addSubview:tweetView];
stackHeight += (int)tweetView.frame.size.height;
}
self.frame = NSMakeRect(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, stackHeight);
}
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor colorWithCalibratedRed:0.96 green:0.96 blue:0.96 alpha:1.0] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
}
- (void)setTweets:(NSArray *)tweets {
_tweets = tweets;
}
- (NSArray *)tweets {
return _tweets;
}
@end
当我运行这个程序滚动视图将只显示正常,但我不能用我的触摸板滚动它。滚动条也不出现。当我调整窗口的大小时,滚动条会像通常在Cocoa应用程序中那样出现一秒钟,如果我很快,我可以通过拖动滚动条来滚动。所以我认为滚动视图确实存在,但它不响应我的鼠标和手势。
我在这里做错了什么?我正在运行Mountain Lion和Xcode 4.4,并且在滚动视图前没有任何视图。 在此先感谢!
您的自定义视图是否足够高,需要滚动才能看到整个事物? – rdelmar 2012-07-27 15:46:22
这是,我可以滚动滚动条,当我调整窗口大小后可见,但我不能使用默认手势滚动。 – icant 2012-07-27 16:36:29