0

我的应用程序顶部有一个半透明图像的视图,我需要在该视图上显示一个 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];



}
4

1 回答 1

0

I am not sure as to what exactly your question is, but if you want to figure out a way to rotate the cube,you'll need some coordinates which specify its edges and vertices. i have a rotating cube for my project, which uses rotation matrices to find the final coordinates of it. you need to feed in the angle through which you have to rotate.to 'turn' it, you need to go through the angle in steps of whatever speed/precision you like and keep a specific pause between successive calls of the 'view' cube function so that it rotates gradually. showing the cube works in matlab using the 'patch' command.maybe there's some similar function in ios dev.

于 2012-05-30T21:47:36.160 回答