4

嗨,我已经搜索了很多自定义相机叠加视图。我找到了几乎很多示例项目,但我仍然无法得到我想要的完美答案。我的问题是我想在按钮上实现自定义相机instagrampicyou其他社交网络应用程序单击使用相机叠加视图打开自定义相机。我已经创建了自定义相机,它工作正常,但我想访问按钮操作,例如在捕获图像时它应该通过使用导航到其他视图UINavigationController但它不起作用。我已经使用此代码来调用相机覆盖视图。

-(void)OpenCamera
{
    //create an overlay view instance
    OverlayView *overlay = [[OverlayView alloc]
                            initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];

    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self; 
    //        picker.allowsEditing = YES;
    picker.allowsEditing = NO;
    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) 
    {
        //set source to video!
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        //hide all controls
        picker.showsCameraControls = NO;
        picker.navigationBarHidden = YES;
        picker.toolbarHidden = YES;
        //make the video preview full size
        picker.wantsFullScreenLayout = YES;
        picker.cameraViewTransform =
        CGAffineTransformScale(picker.cameraViewTransform,
                               CAMERA_TRANSFORM_X,
                               CAMERA_TRANSFORM_Y);
        //set our custom overlay view
        picker.cameraOverlayView = overlay;
//        picker.delegate = overlay;

//        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:picker];

        //show picker
        [self presentModalViewController:picker animated:YES];  
    }
    else
    {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        picker.delegate = self;
        [self presentModalViewController:picker animated:YES];
    }
    [picker release];
}

这是我使用的相机覆盖视图.m 文件代码@interface OverlayView : UIView

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
    //clear the background color of the overlay
//    self.opaque = NO;
//    self.backgroundColor = [UIColor clearColor];

    UIToolbar *toolbar = [UIToolbar new];

    toolbar.barStyle = UIBarStyleBlackTranslucent;

    // create a bordered style button with custom title

    UIBarButtonItem *Cancel = [[[UIBarButtonItem alloc] initWithTitle:@"Cancel"

                                                                  style:UIBarButtonItemStyleBordered    

                                                                 target:self

                                                                 action:@selector(btnCancel:)] autorelease];

    UIBarButtonItem *flexibleSpace1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *Camera = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(btnCapture:)] autorelease]; 

    UIBarButtonItem *flexibleSpace2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *Album = [[[UIBarButtonItem alloc] initWithTitle:@"Gallery"

                                                                   style:UIBarButtonItemStyleBordered

                                                                  target:self

                                                                  action:@selector(btnLibrary:)] autorelease];

    NSArray *items = [NSArray arrayWithObjects: 

                      Cancel,
                      flexibleSpace1,
                      Camera,
                      flexibleSpace2,
                      Album,

                      nil];

    toolbar.items = items;

    // size up the toolbar and set its frame

    // please not that it will work only for views without Navigation toolbars. 

    [toolbar sizeToFit];

    CGFloat toolbarHeight = [toolbar frame].size.height;

    CGRect mainViewBounds = self.bounds;

    [toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),

                                 CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),

                                 CGRectGetWidth(mainViewBounds),

                                 toolbarHeight)];

    [self addSubview:toolbar];
}
return self;
}

-(void)btnLibrary:(id)sender
{

}

-(void)btnCapture:(id)sender
{

}

-(void)btnCancel:(id)sender
{
//    [self dismissModalViewControllerAnimated:YES];
}

一切正常,但正如我所说,我想访问按钮方法和 UINavigationController 来更改视图instagrampicyou但它不能正常工作,你能指导我如何导航到另一个视图吗?

4

0 回答 0