如何通过点击iphone sdk标签栏中的标签打开相机?

时间:2012-05-15 04:59:03

标签: iphone camera uitabbarcontroller uiimagepickercontroller

如何通过单击标签栏应用程序中的选项卡打开相机,我还要自定义该相机控制器?我见过许多类似这样的应用程序,它们还有其他功能,例如instagram这也是这样使用pinterest这是另一个picplz我用google搜索了一些链接,但我没有得到完美的结果我试图通过- (void)viewWillAppear:(BOOL)animated打开相机,但它不能完美,任何身体都可以引导我创建相机视图,如上面的一些应用程序?

我看过这个苹果example.我自己看到的相机的自定义视图this.

嘿,有人有任何答案吗?

2 个答案:

答案 0 :(得分:-1)

试试这段代码。

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
picker.delegate = self; 
picker.allowsEditing = YES;
if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])) 
{
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentModalViewController: picker animated:YES]; 
}
else
{
        // Put alert no camer found
}
[picker release];

答案 1 :(得分:-4)

- (IBAction)buttonTap:(id)sender
{
    UIActionSheet * theActionSheet;

    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        theActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:NSLocalizedString(@"Choose existing photo", nil) otherButtonTitles:nil, nil, nil];
        self.actionSheet = theActionSheet;
    }
    else
     {
         theActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:NSLocalizedString(@"Take photo", nil) otherButtonTitles:NSLocalizedString(@"Choose existing photo", nil), nil, nil];
         self.actionSheet = theActionSheet;
     }
     self.actionSheet.tag = 100;
     self.actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
     [self.actionSheet showInView:self.view.window];    // show from our table view (pops up in the middle of the table)
     [theActionSheet release];      
}