我有一个popoverview问题,点击并打开相机的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];
}
}
在点击按钮之前,弹出窗口显示
同时点击拍摄照片(Neem照片按钮).POPOVERVIEW SIZE自动延伸,如taht
但是我也需要一个相同尺寸的popoverview,同时打开相机
先谢谢......
答案 0 :(得分: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];
}
}