2012-07-25 61 views
2

我有一個popoverview問題,同時點擊打開攝像頭的iPad,我寫的代碼一樣,uipopover問題,同時點擊打開攝像頭的iPad

-(IBAction)business_takephotobtnClicked // click the button show the popoverview 

{ 

NSLog(@"business_takephotobtnClicked"); 
    appdelegate.takePhoto=2; 

    popover = [[UIPopoverController alloc] 
       initWithContentViewController:imgclass]; 

    popover.popoverContentSize = CGSizeMake(138,66); 
    [popover presentPopoverFromRect:popbtn_business.bounds inView:popbtn_business 
    permittedArrowDirections:UIPopoverArrowDirectionUp + 
    UIPopoverArrowDirectionLeft 
    animated:YES]; 
} 





-(IBAction) takePhoto:(id)sender // to open the camera 

{ 




    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    { 

     self.contentSizeForViewInPopover=CGSizeMake(138,66); 




     UIPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     [self presentModalViewController:self.UIPicker animated:YES]; 

    } 
    else { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Camera is not available" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 


    } 

} 

之前單擊該按鈕的酥料餅一樣,顯示enter image description here

同時單擊拍攝照片(照片印楝按鈕)。該POPOVERVIEW大小自動推廣的像taht enter image description here

但我需要一個同樣大小的popoverview同時開啓相機還

先謝謝了......

+0

檢查此鏈接:-http://stackoverflow.com /問題/ 3458722/uipopovercontroller-自動調整大小到最大高度上,pushviewcontroller – Leena 2012-07-27 07:06:08

回答

5

,而不是使用XIB使用以編程方式創建攝像機視圖,並做類似下面的

-(IBAction)popbtn_Click:(id)sender 
{ 
    UIViewController* popoverContent = [[UIViewController alloc] init]; 
    UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 230, 180)]; 
    popoverView.backgroundColor = [UIColor whiteColor]; 

    take_btn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [take_btn setTitle:@"Take" forState:UIControlStateNormal]; 
    take_btn.frame=CGRectMake(2,2, 250, 60); 
    [take_btn addTarget:self action:@selector(take_btnclick:) forControlEvents:UIControlEventTouchUpInside]; 
    [popoverView addSubview:take_btn]; 
} 

-(void)take_btnclick:(id)sender 
{ 
    [popoverController dismissPopoverAnimated:YES]; 

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    { 
     UIPicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     [self presentModalViewController:self.UIPicker animated:YES]; 

     [popoverController dismissPopoverAnimated:YES]; 
    } 
    else { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Camera is not available" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 

    if (popoverController != nil) 
    { 
     [popoverController dismissPopoverAnimated:YES]; 
    } 
}