如何在超级视图中移动子视图 [英] how to move subviews inside a super view
本文介绍了如何在超级视图中移动子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用鼠标在超级视图(使用osx 10.6)中移动子视图?
我已经使用for循环以编程方式创建了五个NSimageView作为子视图.
如何选择并拖动每个图像视图
how to move subviews inside a super view (using osx 10.6) using mouse?
i have programmatically created five NSimageView's as subviews using for loop..
how to select and drag each imageview
推荐答案
最终我得到了答案
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (NSView *)hitTest:(NSPoint)aPoint
{
NSEnumerator *subviews = [[self subviews] objectEnumerator] ;
NSView *hitView ;
NSLog(@"hit");
fHitView = nil ;
while (hitView = [subviews nextObject]) {
NSRect frame = [hitView frame] ;
if (NSPointInRect(aPoint,frame))
if ([hitView isKindOfClass:[DraggableView class]] && ![(DraggableView *)hitView dragEnabled]) {
return hitView ;
}
else {
fHitView = hitView ;
fHitPoint = aPoint ;
fFrameWhenHit = [hitView frame] ;
return self ;
}
}
return nil ;
}
- (void)mouseDragged:(NSEvent *)theEvent
{
if (fHitView != nil) {
NSPoint locationInWindow = [theEvent locationInWindow] ;
NSPoint locationInMySelf = [self convertPoint:locationInWindow fromView:[[self window] contentView]] ;
[fHitView setFrame:NSOffsetRect(fFrameWhenHit,locationInMySelf.x - fHitPoint.x, locationInMySelf.y - fHitPoint.y)] ;
[self setNeedsDisplay:YES] ;
}
}
插入NSview的子类,并将NScustomView类的类名称更改为子类名称...
insert into subclass of NSview and change the class name of NScustomView class as subclass name...
这篇关于如何在超级视图中移动子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文