MonoTouch 中的简单 iPhone 图表应用程序
我有一个规范,将非常简单的图表功能构建到 MonoTouch 应用程序中。到目前为止我必须做的所有事情都是基于表格的,所以这是一个新领域。
在应用程序商店中可以找到许多图表示例,例如 MindMeister 和 SimpleMind 思维导图应用程序。
我需要用户能够单击视图来“放下”新形状、为其添加标签,并可选择将其连接到现有形状。
实现这种交互功能的好方法是什么?我的第一个方法是放下一个从自定义图像创建的 UIImageView,然后确保它可以响应触摸事件来移动它。但是,当您想要添加文本叠加时,事情会变得更加复杂,因为您必须管理两个视图(图像和文本)。
我可以采取什么方法?
PS:如果这不适合SO,请随意打击!
更新:可以通过使用简单的标签覆盖来实现基本图表元素:
UILabel lbl = new UILabel(new RectangleF(...));
lbl.Text = "Whatever";
lbl.Layer.BorderWidth = 3f;
lbl.Layer.BorderColor ( new CGColor (1f, 0f, 0f) );
this.Add (lbl);
可以通过扩展 gui 元素类并覆盖 TouchesBegan
、TouchesMoved< 来实现一些交互性/code> 和
TouchesEnd
事件。
I have a specification to build a very simple diagramming capability into a MonoTouch app. Everything I've had to do up to now has been table based so this is new territory.
Numerous examples of diagramming can be found in the app store, for example the MindMeister and SimpleMind mindmapping apps.
I need users to be able to click on a view to "put down" a new shape, label it, and optionally connect it to an existing shape.
What would be a good approach to achieve this kind of interactive functionality? My first would be to put down a UIImageView
created from a custom image, and then ensuring that it can respond to touch events to move it around. However, when you want to add a text overlay, matters become more complicated as you'd have to manage two views (both the image and the text).
What approach could I follow?
PS: Smite at will if this is inappropriate for SO!
Update: Basic diagram elements can be achieved by using a simple label override:
UILabel lbl = new UILabel(new RectangleF(...));
lbl.Text = "Whatever";
lbl.Layer.BorderWidth = 3f;
lbl.Layer.BorderColor ( new CGColor (1f, 0f, 0f) );
this.Add (lbl);
Some interactivity can be achieved by extending the gui element class and overriding the TouchesBegan
, TouchesMoved
and TouchesEnd
events.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想做的事情并没有那么难。我还没有准备好示例,但我会给您一些可能帮助您入门的步骤。
UIView.这会保持你的形状
和文字。
UIImageView 将保存您的
形状和文本的 UILabel。
方法。在其中您可以将视图的内容复制到图像上下文。
到另一层。
用户触及您的自定义
视图的超级视图。
简单示例:
这个示例非常简单,不应该按原样使用。例如,您应该提供何时接收自定义视图内容的逻辑。如果你像这样保留它,每次调用 Draw 方法时,它都会创建一个新的上下文。您只需执行一次此操作。
将内容复制到图层后,您可以通过超级视图将该图层移动到您想要的任何位置,方法是将其添加到超级视图的图层并修改其框架。您不必为您的超级视图创建另一个自定义视图,您只需创建一个自定义 UIGestureRecognizer,覆盖其自己的 Touches* 方法并将其添加到超级视图中。
这样,您就有一个可以移动的对象(图层)来保存您的形状和文本。
我希望这有帮助。
What you want to do is not that difficult. I do not have an example ready, but I will give you some steps that might help you getting started.
UIView. This will hold your shape
and text.
UIImageView that will hold your
shape and a UILabel for the text.
method. Inside it you can copy the contents of the view to an image context.
to another layer.
to user touches on your custom
view's superview.
Simple example:
This example is quite simple and should not be used as it is. For example, you should provide logic for when to receive the contents of your custom view. If you leave it like this, every time the Draw method gets called it will create a new context. You only need to do this once.
After copying the contents to a layer, you can move around that layer anywhere you want through your superview, by adding it to your superview's layer and modifying its frame. You do not have to create another custom view for your superview, you can just create a custom UIGestureRecognizer, override its own Touches* methods and add it to the superview.
This way you have one object to move around (the layer) that holds both your shape and your text.
I hope this helps.