在UIViewController上画一条线 [英] Draw a line over UIViewController

查看:167
本文介绍了在UIViewController上画一条线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iPhone上的应用程序带有一个UIViewController,里面有一些东西..图像,文本框等...
有没有办法直接在UIViewController中使用opengl画一条线或类似的东西?

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

提前感谢

推荐答案

您确定OpenGL吗?

Are you sure about the OpenGL?

我认为在常规视图上方使用OpenGL是不可能的。

I believe it will be impossible to use OpenGL above regular views.

您可以添加自定义视图(继承来自UIView)在所有其他视图之上,并在该视图上绘制任何想要的内容。

此视图应具有透明背景颜色。

此外,如果您想要进行交互与其他视图(点击按钮,编辑文本视图,滚动等)然后你必须在自定义视图中实现hitTest方法,以便将触摸事件传递给位于此视图下的视图...

You might add a custom view (inherit from UIView) above all the other views and draw anything you want on that view.
This view should have a transparent background color.
In addition, if you want to interact with the other views (tap buttons, edit text views, scroll etc.) then you will have to implement the hitTest method in your custom view in order to pass the touch event to the views that are located under this one...

编辑:不要乱用hitTest。只需取消选中XIB中启用的用户交互...

Don't mess with the hitTest. Just uncheck the User Interaction Enabled in the XIB...

编辑:代码示例:

@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

这篇关于在UIViewController上画一条线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆