我的应用程序顶部有一个半透明图像的视图,我需要在该视图上显示一个 3D 立方体(甚至是一个 3D 外观相似的立方体 - 由 3 个多边形组成)。
立方体的每个面都是可触摸的,并且一旦被触摸就应该被识别。即,用它的 ID 触发一个事件,或者每次触发它自己的事件,这反过来又会转动立方体......我怎样才能做到这一点?
我将尝试想象我所追求的:
所以,从这个显示的立方体开始......
摸红脸后
这段代码只是显示了一个触发事件的简单可触摸按钮,这就是我现在所拥有的
@implementation cubeView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setBackgroundColor:[UIColor clearColor]];
UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Label.png"]];
// For RETINA DISPLAY create an image named Label@2x.png and make it twice big in x and in y
[self addSubview:view];
UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(20,20,100,30)];
[lbl setText:@"Hello"];
[lbl setBackgroundColor:[UIColor clearColor]];
[self addSubview:lbl];
}
return self;
}
视图控制器
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *container = [[[UIView alloc] initWithFrame:CGRectMake(100, 0, 400, 200)]
autorelease];
[self.view addSubview:container];
container.alpha = 0.2;
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(0, 0, 201, 98);
cubeView *cb = [[[SS alloc] initWithFrame:CGRectMake(0, 0, 201, 98)] autorelease];
[b setImage:[self imageWithView:cb] forState:UIControlStateNormal];
[container addSubview:b];
[b addTarget:self action:@selector(clicked:)forControlEvents:UIControlEventTouchUpInside];
}