http://f.cl.ly/items/350X3c0h0A0k3s3f1R1h/Screen%20Shot%202012-03-27%20at%202.53.41%20PM.png
我正在开发一款应用程序,它允许用户在OS X的一段音频中选择一段时间。我大部分搜索功能都是从QuickTime X获得类似上述修剪界面的用户界面,但很不幸出现了许多iOS相关的API 。
我的第一个直觉是,这是一个高度定制的NSSlider 。 在尝试创建这个方向时,我应该采取一个大方向吗? NSSlider是最佳路线吗? 任何指针,提示或代码将不胜感激。
编辑:关于这可能是一个自定义控件有一个很好的评论。 任何指导都将不胜感激!
http://f.cl.ly/items/350X3c0h0A0k3s3f1R1h/Screen%20Shot%202012-03-27%20at%202.53.41%20PM.png
I'm working on an application that'll allow a user to select a range of time in a piece of audio for OS X. Most of the searching I've done around getting a UI like the above trimming interface from QuickTime X has unfortunately turned up many iOS related APIs.
My first instinct is that this is a heavily customized NSSlider. Is there a general direction I should go in when attempting to create this? Is NSSlider the best route? Any pointers, tips or code would be greatly appreciated.
EDIT: There was a good comment about this possibly being a custom control. Any guidance on that would be greatly appreciated as well!
最满意答案
创建一个自定义控件。 以下是我为自定义控件所做的操作:
首先是界面:
@interface AS_CustomControl : NSControl <NSCoding> { } @end然后执行:
@implementation AS_CustomControl -(id)initWithFrame:(NSRect)rect { if (self = [super initWithFrame:rect]) { [self initCustomControl]; } return self; } -(id)initWithCoder:(NSCoder*)coder { if (self = [super initWithCoder:coder]) { [self initCustomControl]; } return self; } -(void)initCustomControl { // put any custom initialization here // such as default variable state } -(void)dealloc { [super dealloc]; } -(void)encodeWithCoder:(NSCoder*)coder { [super encodeWithCoder:coder]; } +(Class)cellClass { return [NSActionCell class]; } @endcellClass方法可确保您的自定义控件在用户与其交互时触发操作消息。
它应该只是一个在drawRect中绘制波形的例子:并且覆盖mouseDown:mouseDragged:和mouseUp:消息来处理范围选择。
Create a custom control. Here's what I do for my custom controls:
First the interface:
@interface AS_CustomControl : NSControl <NSCoding> { } @endThen the implementation:
@implementation AS_CustomControl -(id)initWithFrame:(NSRect)rect { if (self = [super initWithFrame:rect]) { [self initCustomControl]; } return self; } -(id)initWithCoder:(NSCoder*)coder { if (self = [super initWithCoder:coder]) { [self initCustomControl]; } return self; } -(void)initCustomControl { // put any custom initialization here // such as default variable state } -(void)dealloc { [super dealloc]; } -(void)encodeWithCoder:(NSCoder*)coder { [super encodeWithCoder:coder]; } +(Class)cellClass { return [NSActionCell class]; } @endThe cellClass method ensures that your custom control will fire action messages when the user interacts with it.
It should then just be a case of drawing the waveform in drawRect: and overriding the mouseDown: mouseDragged: and mouseUp: messages to handle the range selection.
更多推荐
发布评论