2013-07-10 52 views
1

我正在玩一個cameraOverLayView,並遇到一個奇怪的行爲。在呈現UIImagePickerController之前,我將allowedEditing設置爲YES。捕獲屏幕出現後,我點擊一個觸發takePicture()的按鈕。代替方法didFinishPickingMediaWithInfo()會被立即調用,而不是呈現編輯屏幕。任何人都可以幫我弄清楚我可能做錯了什麼?我粘貼下面的一些代碼...UIImagePickerController不顯示編輯屏幕

謝謝!

- (BOOL)shouldStartCameraController { 

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) { 
     return NO; 
    } 

    CGSize screenSize = [[UIScreen mainScreen] bounds].size; 
    float overlayOffset = 0; 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
     if (screenSize.height > 480.0f) { 
      overlayOffset = 195; 
     } else { 
      overlayOffset = 103; 
     } 
    } else { 
     /*Do iPad stuff here.*/ 
    } 


    UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init]; 
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] 
     && [[UIImagePickerController availableMediaTypesForSourceType: 
      UIImagePickerControllerSourceTypeCamera] containsObject:(NSString *)kUTTypeImage]) { 

     cameraUI.mediaTypes = [NSArray arrayWithObject:(NSString *) kUTTypeImage]; 
     cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera; 

     if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) { 
      cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceRear; 
     } else if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) { 
      cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
     } 

    } else { 
     return NO; 
    } 


    UIView *cameraOverlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height)]; 
    UIImageView *cameraOverlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"iphone5_camera_overlay.png"]]; 
    cameraOverlayImageView.frame = CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height); 
    [cameraOverlayView addSubview:cameraOverlayImageView]; 


    UILabel *cameraLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, self.view.bounds.size.height-overlayOffset, self.view.bounds.size.width, 50.0f)]; 
    [cameraLabel setTextAlignment:NSTextAlignmentCenter]; 
    [cameraLabel setBackgroundColor:[UIColor clearColor]]; 
    [cameraLabel setTextColor:[UIColor whiteColor]]; 
    [cameraLabel setShadowColor:[UIColor colorWithWhite:0.0f alpha:0.300f]]; 
    [cameraLabel setShadowOffset:CGSizeMake(0.0f, -1.0f)]; 
    [cameraLabel setFont:[UIFont boldSystemFontOfSize:18.0f]]; 
    [cameraOverlayView addSubview:cameraLabel]; 

    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [cancelButton addTarget:self action:@selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchDown]; 
    [cancelButton setFrame:CGRectMake(10, cameraOverlayView.frame.size.height-60, 50, 50)]; 
    [cancelButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]]; 
    [cameraOverlayView addSubview:cancelButton]; 


    UIButton *snapButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [snapButton addTarget:self action:@selector(takePictureButtonPressed:) forControlEvents:UIControlEventTouchDown]; 
    [snapButton setFrame:CGRectMake(110, cameraOverlayView.frame.size.height-60, 100, 50)]; 
    [snapButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]]; 
    [cameraOverlayView addSubview:snapButton]; 
    cameraUI.allowsEditing = YES; 
    cameraUI.showsCameraControls = NO; 
    cameraUI.delegate = self; 
    self.imagePickerController = cameraUI; 

    [self presentModalViewController:cameraUI animated:YES]; 

    return YES; 
} 


- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer { 
    [self shouldPresentPhotoCaptureController]; 
} 

#pragma mark - UIBarButton Selectors 

- (void)takePictureButtonPressed:(id)sender { 
    NSLog(@"takePictureButtonPressed..."); 
    // TODO: take picture! 
    [self.imagePickerController takePicture]; 

} 

回答

0

可能dublicate:How do I use [camera takePhoto] and edit using UIImagePicker - UIImagePickerController.allowsEditing = YES

根據takePicture:方法蘋果文檔中:

使用此方法與自定義背景畫面視圖一起啓動靜止圖像的程序捕獲。這支持在不離開界面的情況下拍攝多張照片,但要求您隱藏默認的圖像選取器控件。

調用此方法而被捕獲的圖像沒有任何影響。 必須等到關聯的委託對象收到imagePickerController:didFinishPickingMediaWithInfo:消息後才能捕獲其他圖片。

看來,這種方法(自定義覆蓋)它配置爲了自己管理。即使「allowsEditing = YES」,拍攝的照片也會直接發送到imagePickerController:didFinishPickingMediaWithInfo :.

此基礎上,如果我們想用我們的自定義用戶界面編輯拍攝的照片,我們應該創建用於該目的的根據自定義編輯屏幕。

+0

可能的重複被重定向到另一個可能的重複。 – MendyK

相關問題