ghi*_*boz 1 iphone opengl-es uiviewcontroller
我的iPhone上的应用程序带有UIViewController,其中包含一些内容..图像,文本框等...有没有办法在UIViewController中直接使用opengl绘制一条线或类似的东西?
提前致谢
你确定OpenGL吗?
我相信在常规视图之上使用OpenGL是不可能的.
您可以在所有其他视图上方添加自定义视图(从UIView继承),并在该视图上绘制任何所需内容.
此视图应具有透明背景颜色.
此外,如果您想与其他视图交互(点击按钮,编辑文本视图,滚动等),那么您必须在自定义视图中实现hitTest方法,以便将触摸事件传递给位于的视图在这一个......
编辑:不要乱用hitTest.只需取消选中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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12317 次 |
| 最近记录: |