2010-09-06 7 views
0
problème

à ajouter deuxième UIButton à cameraOverlayView, ici, je suis en mesure d'ajouter le premier bouton, mais pas en mesure d'ajouter deuxième bouton avec le code suivantà ajouter deuxième UIButton dans cameraOverlayView

- (void)pickAndDecodeFromSource:(UIImagePickerControllerSourceType) sourceType { 
    [self reset]; 

    // Create the Image Picker 
    if ([UIImagePickerController isSourceTypeAvailable:sourceType]) { 
    UIImagePickerController* aPicker = 
     [[[UIImagePickerController alloc] init] autorelease]; 
    aPicker.sourceType = sourceType; 
    aPicker.delegate = self; 
    self.picker = aPicker; 


    // [[NSUserDefaults standardUserDefaults] boolForKey:@"allowEditing"]; 
    BOOL isCamera = (sourceType == UIImagePickerControllerSourceTypeCamera); 
    if ([picker respondsToSelector:@selector(setAllowsEditing:)]) { 
     // not in 3.0 
     [picker setAllowsEditing:!isCamera]; 
    } 
    if (isCamera) { 
     if ([picker respondsToSelector:@selector(setShowsCameraControls:)]) { 
     [picker setShowsCameraControls:NO]; 
     UIButton *cancelButton = 
      [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
     NSString *cancelString = 
      NSLocalizedString(@"DecoderViewController cancel button title", @""); 
     CGFloat height = [UIFont systemFontSize]; 
     CGSize size = 

      [cancelString sizeWithFont:[UIFont systemFontOfSize:height]]; 
     [cancelButton setTitle:cancelString forState:UIControlStateNormal]; 
      //cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"CancelButtonForButton.png"]]; 
      //cancelButton.backgroundColor = [UIColor clearColor]; 
      //cancelButton.backgroundColor = [UIColor greenColor]; 
      [cancelButton setImage:[UIImage imageNamed:@"cancelForButton.png"] forState:UIControlStateNormal]; 
      //[cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 

     CGRect appFrame = [[UIScreen mainScreen] bounds]; 
     static const int kMargin = 10; 
     static const int kInternalXMargin = 10; 
     static const int kInternalYMargin = 10; 
     CGRect frame = CGRectMake(kMargin, 
      appFrame.size.height - (height + 2*kInternalYMargin + kMargin), 
      2*kInternalXMargin + size.width, 
      height + 2*kInternalYMargin); 
     [cancelButton setFrame:frame]; 
     [cancelButton addTarget:self 
         action:@selector(cancel:) 
       forControlEvents:UIControlEventTouchUpInside]; 
     picker.cameraOverlayView = cancelButton; 
     // The camera takes quite a while to start up. Hence the 2 second delay. 
     [self performSelector:@selector(takeScreenshot) 
        withObject:nil 
        afterDelay:2.0]; 
      //cancelButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]]; 
     } 
    } 

    // Picker is displayed asynchronously. 
    [self presentModalViewController:picker animated:YES]; 
    } else { 
    NSLog(@"Attempted to pick an image with illegal source type '%d'", sourceType); 
    } 
} 

Répondre

1

Le problème est que vous êtes remplacer la superposition de la caméra par le premier bouton - créant ainsi le second bouton et utilisant "picker.cameraOverlayView = newButton;" remplace à nouveau la superposition de la caméra.

La solution consiste à créer un UIView parent, à y ajouter les deux boutons, puis à définir l'incrustation de la caméra comme UIView parent.

+0

ya j'ai essayé la même chose et cela a fonctionné merci beaucoup. – mrugen