How to use switch between different modes in UIImagePickerController's custom controls?

时光怂恿深爱的人放手 提交于 2019-12-12 06:24:10

问题


picker.showsCameraControls = NO;
picker.cameraOverlayView = someView;

As I will add some custom view to showCameraControls, then how can I switch in between modes, like native app of iphone switches between camera and recording, same as I want to switch between camera and one more camera having button on it, how can I do it? Help !


回答1:


This sample project shows you how to make your own custom overlay for the UIImagePickerController, and how to use it. For more info on what each of the properties and methods do for the UIImagePickerController, refer here. Hope that helps!




回答2:


In your custom view, you will have one button setup with the picker as target and it's takePicture method. Then you would have another button, or switch, or however you want to go to your custom mode, and there you would have one button to start/stop snapping. This button should have self for target (self as the view controller that you presented the picker from) and a custom toggleSnapping method. You also need to set yourself as a delegate to image picker to get notified when each picture is taken. Oh, and a BOOL instance variable that tracks if snapping is currently active or not. Then your toggleSnapping method could look something like this:

- (void)toggleSnapping
{
    isSnapping = !isSnapping; // (this will reverse NO to YES and vice-versa)
    [picker takePicture]; // starts taking 1st picture, delegate will take care of rest
    if (isSnapping) {
        // configure your button to show stop icon
    } else {
        // configure your button to show start snapping icon
    }
}

And you would need to implement picker's delegate method in which you simply start another picture if isSnapping is currently YES:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // save the snapped picture to the camera roll

    if (isSnapping) { // if burst mode is on, take another picture
        [picker takePicture];
    }
}


来源:https://stackoverflow.com/questions/7020475/how-to-use-switch-between-different-modes-in-uiimagepickercontrollers-custom-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!