Draw a line above the UIViewController

I have an iPhone app with a UIViewController with some things inside. image, textbox etc ... is there a way to draw a line or something like this using opengl directly inside the UIViewController?

early

+1
iphone uiviewcontroller opengl-es
Jun 09 '10 at 6:14
source share
3 answers

Are you sure OpenGL?

I believe that using OpenGL over regular views will be impossible.

You can add a custom view (inherit from UIView) above all other views and draw whatever you want in that view.
This view should have a transparent background color.
In addition, if you want to interact with other views (click buttons, edit text views, scroll, etc.), you will need to implement the hitTest method in your custom view in order to send a touch event to the points below it. .

EDIT: Do not mess with hitTest. Just uncheck User Interaction Enabled in XIB ...

EDIT: Code Example:

@interface TransparentDrawingView : UIView { CGPoint fromPoint; CGPoint toPoint; } - (void)drawLineFrom:(CGPoint)from to:(CGPoint)to; @end @implementation TransparentDrawingView - (void)initObject { // Initialization code [super setBackgroundColor:[UIColor clearColor]]; } - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { // Initialization code [self initObject]; } return self; } - (id)initWithCoder:(NSCoder *)aCoder { if (self = [super initWithCoder:aCoder]) { // Initialization code [self initObject]; } return self; } - (void)drawRect:(CGRect)rect { // Drawing code // Draw a line from 'fromPoint' to 'toPoint' } - (void)drawLineFrom:(CGPoint)from to:(CGPoint)to { fromPoint = from; toPoint = to; // Refresh [self setNeedsDisplay]; } @end 
+6
Jun 09 '10 at 6:23
source share

At first I think you should know the responsibilities of UIView and UIViewController. UIView is mainly responsible for drawing (cancels touchBegin, ToucheMove, etc.), animates, controls subviews and processes the event; The UIViewController is mainly responsible for loading, unloading views, etc.

So, you should "draw" this line in your individual view (UIView), and not view the controller.

Second: if you need to display only simple shapes or lines. I suggest you use the controls and images of the user interface. Even "drawRect" is not recommended, as this will lead to more resources being used. Of course, OpenGL needs a lot of resources.

+1
Jun 09 '10 at 7:21
source share

The answer is quite simple, you need to create a new class that extends UIView and redefine the drawRect function to draw (using Quartz ...) your line. Use this method if you want to also use the gradient background.

I am also developing Adobe Flex 4, and I notice that the iPhone SDK does not have β€œtemplates” for skins and layouts such as Flex 4 (for example, UIView can have Skin (in a separate file ..) and layout (horizontal, vertical, tile). ...)), for me it's a terrible shortage!

Something that the three20 open library is trying to bring to the iPhone SDK.

+1
Jul 25 '10 at 9:05
source share



All Articles