基于QuickTIme X的修剪UI创建自定义NSSlider(Creating a Custom NSSlider Based Off of QuickTIme X's Trim UI)

系统教程 行业动态 更新时间:2024-06-14 16:59:47
基于QuickTIme X的修剪UI创建自定义NSSlider(Creating a Custom NSSlider Based Off of QuickTIme X's Trim UI)

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]; } @end

cellClass方法可确保您的自定义控件在用户与其交互时触发操作消息。

它应该只是一个在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> { } @end

Then 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]; } @end

The 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.

更多推荐

本文发布于:2023-04-17 09:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/8ddef8e25d24d7ddada8affefa9d5ca7.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   NSSlider   QuickTIme   UI   Based

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!