iPhone相机没有显示

时间:2012-01-09 05:43:43

标签: iphone ios ios4 iphone-sdk-3.0

加载视图时未显示相机。相反,它显示了我设计的视图。在按钮操作中给出代码时,代码运行良好。 任何人都可以帮忙吗?代码如下

- (void)viewDidLoad {
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
    scroll_under.contentSize=CGSizeMake(1000,50);
    if(scroll_under.contentOffset.x==0)
    {   
        leftArrow.hidden=TRUE;
    }
    if(scroll_under.contentOffset.x==429)
    {
        rightArrow.hidden=TRUE;
    }
    if(scroll_under.contentOffset.x>0 && scroll_under.contentOffset.x<429)
    {
        leftArrow.hidden=FALSE;
        rightArrow.hidden=FALSE;        
    }
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;         
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
    [self presentModalViewController:picker animated:YES];
}



- (void)imagePickerController:(UIImagePickerController *)picker   didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
    resultImage.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}

1 个答案:

答案 0 :(得分:1)

要使其正常工作,只需将代码移至:

- (void)viewDidAppear:(BOOL)animated
{
  UIImagePickerController * picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;         
  picker.sourceType = UIImagePickerControllerSourceTypeCamera;
  [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
  [self presentModalViewController:picker animated:YES];
}