在同一个UIPopoverController中创建UISegementControl和UIImagePicker

时间:2013-09-19 04:12:40

标签: ios ipad uiimagepickercontroller uipopovercontroller uisegmentedcontrol

我在UISegementControl中创建UIPopoverController。如何在同一个UIImagePicker中添加UIPopoverController

segmentController *segmentCtrl = [[segmentController alloc] init];
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:segmentCtrl];

UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
[imgPicker setDelegate:self];

UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:navCtrl];
[popOver setPopoverContentSize:CGSizeMake(300, 500) animated:YES];
popOver.delegate = self;
self.popoverImageViewController = popOver;
[self.popoverImageViewController presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

在上面的代码中,它在UIPopoverController中创建了一个UISegementControl。但是我需要在UIPopover中添加UIImagePicker ......

如果我犯了任何错误。请纠正我。

1 个答案:

答案 0 :(得分:0)

尝试做这样的事情。

imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(768, 1000);

NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];

[containerController.view addSubview:imagePickerController.view];
[containerController.view addSubview:segmentedControl];

popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];

[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];

//add ur segment control on top it would take 44 px then adjust the imagePicker frame accordingly.

CGRect tFrame = containerController.view.frame;
tFrame.origin.x -= 44;
tFrame.size.height -=44;
[imagePickerController.view setFrame:containerController.view.frame];