自定义照相机

来源:互联网 发布:手机淘宝心级怎么看 编辑:程序博客网 时间:2024/04/20 02:27


#import <Foundation/Foundation.h>


@interface CustomerViewController : UIImagePickerController<UIImagePickerControllerDelegate,UINavigationControllerDelegate> {
    UIToolbar *hortoolBar;
    UIToolbar *vertoolBar;
    
}
@property (nonatomic,retain) UIToolbar *hortoolBar;
@property (nonatomic,retain) UIToolbar *vertoolBar;

-(void)setNewController;
@end



//  Created by wgd on 12-5-3.

//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "CustomerViewController.h"


@implementation CustomerViewController

@synthesize hortoolBar,vertoolBar;

-(CustomerViewController *)init
{
    [super init];
    [self setNewController];
    return self;
}


-(void)check:(id)sender
{
    self.showsCameraControls = NO;
    [self takePicture];   

}

-(void)cancelTakePhoto:(id)sender
{
    [self.delegate imagePickerControllerDidCancel:self];
}

-(void)setNewController
{
        
    self.vertoolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 970, 768, 54)];
    [self.view addSubview:vertoolBar];
    
    
    UIBarButtonItem *btn1 = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelTakePhoto:)];
    btn1.width = 100;
    
    UIBarButtonItem *btn11 = [[UIBarButtonItem alloc] initWithTitle:@"" style:
                              UIBarButtonItemStylePlain target:self action:nil];
    btn11.width = 530;
    btn11.enabled = NO;
    
    UIBarButtonItem *btn2=  [[UIBarButtonItem alloc] initWithTitle:@"拍照" style: UIBarButtonSystemItemCancel target:self action:@selector(check:)];
//    UIBarButtonItem *btn2=  [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"test.png"] style:UIBarButtonSystemItemCancel target:self action:@selector(check:)];
    btn2.width = 100;
    NSMutableArray *btnArray = [[NSMutableArray alloc] initWithObjects:btn1,btn11,btn2,nil];
    vertoolBar.items = btnArray;
    [btn1 release];
    [btn11 release];
    [btn2 release];
    
    UIBarButtonItem *btn3 = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonSystemItemCancel target:self action:@selector(cancelTakePhoto:)];
    btn3.width = 100;
    UIBarButtonItem *btn31 = [[UIBarButtonItem alloc] initWithTitle:@"" style:
                              UIBarButtonItemStylePlain target:self action:nil];
    btn31.width = 790;
    btn31.enabled = NO;
    
    UIBarButtonItem *btn4=  [[UIBarButtonItem alloc] initWithTitle:@"拍照" style:UIBarButtonSystemItemCancel target:self action:@selector(check:)];
    btn4.width = 100;
    NSMutableArray *btnArray2 = [[NSMutableArray alloc] initWithObjects:btn3,btn31,btn4,nil];
    [btn3 release];
    [btn31 release];
    [btn4 release];
    
    self.hortoolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 714, 1024, 54)];
    hortoolBar.items = btnArray2;
    [self.view addSubview:hortoolBar];
    
    
    if(UIDeviceOrientationLandscapeRight == [UIDevice currentDevice].orientation
       ||UIDeviceOrientationLandscapeLeft == [UIDevice currentDevice].orientation
       )
    {
        vertoolBar.hidden = YES;
        hortoolBar.hidden = NO;
    }
    else
    {
        vertoolBar.hidden = NO;
        hortoolBar.hidden = YES;
    }
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{    
    return  YES;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    
   
    if(UIDeviceOrientationLandscapeRight ==toInterfaceOrientation||
       UIDeviceOrientationLandscapeLeft == toInterfaceOrientation)
    {
        vertoolBar.hidden = YES;
        hortoolBar.hidden = NO;
    
    }
    else
    {
        hortoolBar.hidden = YES;
        vertoolBar.hidden = NO;
    }
}

-(void)dealloc
{
    [vertoolBar release];
    [vertoolBar release];
    [super dealloc];
}

 
@end