2010-09-14 4 views
0

Je jouais avec l'API Arkit ... Je voulais ajouter personnalisée UIButton dans la boîte sur le côté droit qui apparaît à l'écran généré par le code ci-dessous dans le délégué de l'application:personnalisée UIButton dans Arkit programme

#define BOX_WIDTH 350 
#define BOX_HEIGHT 150 

- (UIView *)viewForCoordinate:(ARCoordinate *)coordinate { 

    CGRect theFrame = CGRectMake(0, 0, BOX_WIDTH, BOX_HEIGHT); 
    UIView *tempView = [[UIView alloc] initWithFrame:theFrame]; 

    //tempView.backgroundColor = [UIColor colorWithWhite:.5 alpha:.3]; 

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, 20.0)]; 
    titleLabel.backgroundColor = [UIColor colorWithWhite:.3 alpha:.8]; 
    titleLabel.textColor = [UIColor whiteColor]; 
    titleLabel.textAlignment = UITextAlignmentCenter; 
    titleLabel.text = coordinate.title; 
    [titleLabel sizeToFit]; 

    titleLabel.frame = CGRectMake(BOX_WIDTH/2.0 - titleLabel.frame.size.width/2.0 - 4.0, 0, titleLabel.frame.size.width + 8.0, titleLabel.frame.size.height + 8.0); 

    UIImageView *pointView = [[UIImageView alloc] initWithFrame:CGRectZero]; 
    pointView.image = [UIImage imageNamed:@"location.png"]; 
    pointView.frame = CGRectMake((int)(BOX_WIDTH/2.0 - pointView.image.size.width/2.0), (int)(BOX_HEIGHT/2.0 - pointView.image.size.height/2.0), pointView.image.size.width, pointView.image.size.height); 

    [tempView addSubview:titleLabel]; 
    [tempView addSubview:pointView]; 

    [titleLabel release]; 
    [pointView release]; 

    return [tempView autorelease]; 
} 

Comment puis-je retirer ceci? S'il vous plaît aider!

+0

une chance à ce sujet? J'ai ajouté un UIButton sur ce tempView mais quand j'essaie de cliquer dessus, ça ne fait rien. – Frank

+0

salut, je me demandais juste - avez-vous réussi à rejeter la vue? Si oui, pourriez-vous partager? J'ai quelques problèmes moi-même –

Répondre

0

Voici mon code:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
button.frame = CGRectMake(190, 430, 110, 30); 
[button setTitle:@"Retour au plan" forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(boutonPlan) 
forControlEvents:UIControlEventTouchUpInside]; 

// Si il peut, on effectue la MAJ de la vue 
ParkingAppDelegate *appDelegate = (ParkingAppDelegate *)[[UIApplication sharedApplication] delegate]; 
arvc = [[ARViewController alloc] initWithDelegate:self]; 
//add the button to the view 
[arvc.view addSubview:button]; 

Hope this helps.