【问题标题】:ios imagepickerview cancel button functionalityios imagepickerview取消按钮功能
【发布时间】:2013-02-21 18:56:09
【问题描述】:

无论如何,我的取消按钮都会拉起相机胶卷。如何删除它。

-  (void)cameraButtonClick:(id)sender {
        mediaPicker = [[UIImagePickerController alloc] init];
        //[mediaPicker setDelegate:self];
        mediaPicker.allowsEditing = YES;
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                                     delegate:self
                                                            cancelButtonTitle:@"Cancel"
                                                       destructiveButtonTitle:nil
                                                            otherButtonTitles:@"Take photo", @"Choose Existing", nil];
            [actionSheet showInView:self.view];
        }
        // If device doesn't has a camera, Only "Choose Existing" option will show up.
        else {
            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                                     delegate:self
                                                            cancelButtonTitle:@"Cancel"
                                                       destructiveButtonTitle:nil
                                                            otherButtonTitles:@"Choose Existing", nil];
            [actionSheet showInView:self.view];

        }
    }


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
            if (buttonIndex == 0) {
                [capture showImagePicker:self.navigationController popoverRect:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
            } else if (buttonIndex == 1) {
                capture     = [[VFPhotoCaptureController alloc] init];
            } 
        }
        else{
            if (buttonIndex == 0) {
                capture     = [[VFPhotoCaptureController alloc] init];
            }

        }
        [self presentModalViewController:mediaPicker animated:YES];
    }

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
        [picker dismissModalViewControllerAnimated:YES];
    }

【问题讨论】:

    标签: ios objective-c image camera uiimagepickercontroller


    【解决方案1】:

    您需要更好的操作表按钮处理:

    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
        if (buttonIndex != actionSheet.cancelButtonIndex) {
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                if (buttonIndex == actionSheet.firstOtherButtonIndex) {
                    [capture showImagePicker:self.navigationController popoverRect:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)];
                } else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1) {
                    capture = [[VFPhotoCaptureController alloc] init];
                } 
            } else {
                if (buttonIndex == actionSheet.firstOtherButtonIndex) {
                    capture = [[VFPhotoCaptureController alloc] init];
                }
            }
    
            [self presentModalViewController:mediaPicker animated:YES];
        }
    }
    

    【讨论】:

    • 感谢您的澄清。我刚刚发现问题是最后一行 [self presentModalViewController:mediaPicker animated:YES];我真傻。而且我确实将您的更改合并到了代码中。
    猜你喜欢
    • 1970-01-01
    • 2013-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-10
    • 2012-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多