简体   繁体   English

您可以使用界面生成器在xcode中创建自定义视图吗?

[英]Can you make a custom view in xcode using interface builder?

not a viewcontroller, but an actual view 不是视图控制器,而是实际视图

My app will include a piano keyboard in two separate sections. 我的应用程序将在两个单独的部分中包含一个钢琴键盘。 Instead of duplicating the code for each part, I'd rather make the keyboard a custom view and implement it into the respective viewcontrollers. 我宁愿使键盘成为自定义视图,然后将其实现到相应的视图控制器中,而不是为每个部分复制代码。 However, itseems like it would be a pain to code the position each key, so I was hoping there was someway I could do it visually. 但是,似乎很难对每个键的位置进行编码,所以我希望可以以某种方式直观地进行编码。

And if not, is there a way I could make the keyboard its own viewcontroller, and then add that as a subclass of the viewcontrollers that represent the different sections of the app? 如果不是,是否有办法让键盘成为自己的viewcontroller,然后将其添加为代表应用程序不同部分的viewcontrollers的子类?

Thanks 谢谢

Not sure what you are asking, you can add a View class to your interface and then in under the Utilities Panel > Identity Inspector there is a custom class field which you can change to a Custom subclass of NSView. 不确定您要问的是什么,可以将View类添加到您的界面,然后在“实用工具面板”>“ Identity Inspector”下,有一个自定义类字段,您可以将其更改为NSView的“自定义”子类。

If you want to create your own Customer fire that shows up in interface builder the search for custom IBPlugins, I haven't tried to do this with Xcode 4 so I don't know how much it has changed since Interface Builder was integrated with Xcode 4. Though this is something I have to looking got one of my own custom controls. 如果您想创建自己的Customer fire,以显示在Interface Builder中,以搜索自定义IBPlugins,我没有尝试使用Xcode 4进行此操作,所以我不知道自从Interface Builder与Xcode集成以来,它发生了多大变化4.虽然这是我必须寻找的东西,但我必须拥有自己的自定义控件之一。

So you mean each piano key is a separate UIView, you could have a UIControl subclass (UIView subclass) that contains the key sub views, it would seem to me that it would be easier in you UIContol subclass to add all of the UIView subclasses for each key pragmatically because there is a nice mathematical relationship between each key you could then place your UIControl in twice in your view and set its subclass to you custom UIControl class. 因此,您的意思是每个钢琴键是一个单独的UIView,您可以有一个包含键子视图的UIControl子类(UIView子类),在我看来,在UIContol子类中为所有UIView子类添加更容易务实地使用每个键,因为每个键之间存在良好的数学关系,然后您可以将UIControl放在视图中两次,并将其子类设置为自定义UIControl类。 You could then add you individual key UIView subclasses by overriding -[UIView layoutSubviews] perhaps, you could manually add you key UIView in interface builder if you want, but the seems like a lot more work. 然后,您可以通过覆盖-[UIView layoutSubviews]来添加各个关键的UIView子类,也可以根据需要在界面生成器中手动添加关键的UIView,但似乎还有很多工作要做。 You can have as many instances of your subclass keyboard in interface builder as you want and they don,t each have to have there own UVIewController, you Keyboard sub class can be the target of each key press from each button and then pass that onto the viewcontroller anyway you want, though I don't now how you would deal with polyphony that way if you need that, 您可以根据需要在接口构建器中具有任意数量的子类键盘实例,而它们不必每个都拥有自己的UVIewController,您可以将Keyboard子类作为每个按钮上每个按键的目标,然后将其传递给无论如何,都需要viewcontroller,尽管我现在不知道如何在需要时用这种方式处理复音,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM