How to add UIImagePickerViewController as a subview in ipad.
in iphone i used like this this working fine
self.pick = [[UIImagePickerController alloc]init];
pick.delegate = self;
pick.sourceType = UIImagePickerControllerSourceTypeCamera;
pick.sourceType = UIImagePickerControllerCameraDeviceFront;
pick.showsCameraControls = NO;
CGRect rect = CGRectMake(0, 0, 200, 250);
pick.view.frame = rect;
UIView *cameraView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
[cameraView setBackgroundColor:[UIColor greenColor]];
[cameraView addSubview:pick.view];
[self.view addSubview:cameraView];
[pick viewWillAppear:YES];
[pick viewDidAppear:YES];
[pick release];
but same way i pad is not working. ipad is getting full view when camera is open.
i don't want to use popoverview controller.
pls help me?
UIImagePickerController must be presented with UIPopoverController on iPad.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popOver = popover;
} else {
[self presentModalViewController:picker animated:YES];
}
Related
I am trying to figure out why this tableView is shifted across to the right, it appears in every view the app uses, yet the app itself displays fine, it's only when the tableView appears is everything shifted out of the screen.
I believe the initializing is here;
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"Lets load the frame");
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame: frame];
self.contentSizeForViewInPopover = CGSizeMake(320, 480);
m_mywork = nil;
dataArray = [LoadSessionController loadTableData:YES];
}
Here is the initializing from another class;
on iPad display is perfect.
- (void) ShowInitialMenu
{
InitialMenuController *MewMgrController = [[InitialMenuController alloc] initWithStyle:UITableViewStyleGrouped];
MewMgrController.delegate = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController: MewMgrController];
if(![ColorSplashAppDelegate isiPad]){
[self presentViewController:navController animated:YES completion:nil];
}
else{
UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:navController];
popover.delegate = self;
[popover presentPopoverFromRect:CGRectMake(30.0, 940.0, 30.0, 480.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
ColorSplashAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.popoverController = popover;
}
[navController release];
[MewMgrController release];
[self enableUserAction:YES];
}
Try This.
-(void)viewDidLayoutSubviews
{
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame: frame];
self.contentSizeForViewInPopover = CGSizeMake(320, 480);
m_mywork = nil;
}
Guyz, I am displaying UIImagePickerController in UINavigationController but some frame of image picker controller hides under nav bar .Do any Body has the solution and code is
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
//[picker.view setFrame:CGRectMake(0,50, 800, 600)];
self.nv=[[UINavigationController alloc]init];
[self.nv.view setFrame:(CGRectMake(0, 50, 320.0, 400.0))];
// 4. add the nav bar to the main view
[self.nv addChildViewController:picker];
[picker didMoveToParentViewController:self.nv];
picker.view.frame = CGRectMake(15, 50, 290, 400);
popoverController = [[UIPopoverController alloc] initWithContentViewController:self.nv];
[popoverController presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
Try this alternate. :)
#define ISIPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
UIPopoverController *popover;
- (IBAction)openImagePicker:(UIButton *)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //UIImagePickerControllerSourceTypeCamera
if (ISIPHONE)
{
[self presentViewController:picker animated:YES completion:NULL];
}
else
{
if (!popover)
{
popover = [[UIPopoverController alloc] initWithContentViewController:picker];
}
[popover presentPopoverFromRect:sender.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Using UIPopovercontroller below ios8.0 in iphone working fine with this code. But in ios8 it display white screen.
Code :
pickerController = [[UIViewController alloc] init];
UIView *viewV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
[viewV setBackgroundColor:[UIColor clearColor]];
popOverController = [[UIPopoverController alloc] initWithContentViewController:pickerController];
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
CGRect ImageBtnFrame = [self.view convertRect:sender.frame fromView:self.view];
[popOverController presentPopoverFromRect:ImageBtnFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Any alternative for ios8, need suggestion.
According to 2014 WWDC, in the 30 minute mark, the right answer is:
- (void) tapButton:(id) sender
{
MyViewControllerClass * vc = [[MyViewControllerClass alloc] init];
vc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController * popOverController = vc.popoverPresentationController;
[popOverController setDelegate:self];
popOverController.sourceView = sender;
popOverController.sourceRect = ((UIButton*)sender).frame;
popOverController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:vc
animated:YES
completion:nil];
}
Notice that the accepted answer has some problems like:
Not setting the modalPresentationStyle
Presenting the UIPopoverPresentationController * instead of the UIViewController
Try to use the new iOS 8 API for popovers.
pickerController = [[UIViewController alloc] init];
UIView *viewV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
[viewV setBackgroundColor:[UIColor clearColor]];
UIPopoverPresentationController *popOverController = pickerController .popoverPresentationController;
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
popOverController.sourceView = self.view;
popOverController.sourceRect = sender.frame;
popOverController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:popOverController
animated:YES
completion:nil];
That will cause on iOS 8. So, I recommended to use following Github library.
https://github.com/skywinder/ActionSheetPicker-3.0 or you can write code base on iOS version.
if (OLDER_THAN_IOS_8) {
// Your regular code
pickerController = [[UIViewController alloc] init];
UIView *viewV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
[viewV setBackgroundColor:[UIColor clearColor]];
popOverController = [[UIPopoverController alloc] initWithContentViewController:pickerController];
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
CGRect ImageBtnFrame = [self.view convertRect:sender.frame fromView:self.view];
[popOverController presentPopoverFromRect:ImageBtnFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
} else {
// New Code that support iOS -8 using UIPopoverPresentationController
// Checkout #AndreasZ answer for the same
}
I am trying to make an iPhone app work in an iPad but the UIPopoverController is
comming back with error.
- (IBAction)photoTapped1 {
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
// If in editing state, then display an image picker; if not, create and push a photo view controller.
if (self.editing) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
[imagePicker release];
} else {
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}
}else{
if (self.editing){
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
self.popover.delegate =self;
[popover release];
}else{
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}}}
The error I am getting is:
'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] must not be called with nil.'
Anyone available to give me a hand on this code, I have looked on the internet for solutions and samples but can not seem to make it work.
Thank you.
___ added to original question_____
I am adding the recipePhotoViewController here, I am assuming that ImageView manipulation is the same for iPhone and iPad.
my.h File
#class Recipe;
#interface RecipePhotoViewController : UIViewController {
#private
Recipe *recipe;
UIImageView *imageView;
}
#property(nonatomic, retain) Recipe *recipe;
#property(nonatomic, retain) UIImageView *imageView;
#end
Here is my .m file
#implementation RecipePhotoViewController
#synthesize recipe;
#synthesize imageView;
- (void)loadView {
self.title = #"Photo";
imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.backgroundColor = [UIColor blackColor];
self.view = imageView; }
- (void)viewWillAppear:(BOOL)animated {
imageView.image = [recipe.image valueForKey:#"image"];}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[imageView release];
[recipe release];
[super dealloc];
} #end
You are initializing the popover controller in a wrong way:
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
You should pass the controller you would like to display inside of the popover -- not the popover itself (which is nil since you have not yet initialised it)!
Maybe this would do it for you?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
If this is correct, then you should also present the pop over you have just created: – presentPopoverFromRect:inView:permittedArrowDirections:animated:
-- e.g.:
[self.popover presentPopoverFromRect:sender.frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
where sender is the argument to :
- (IBAction)photoTapped1:(id)sender {
The content of your popover which you store in the variable popover is obviously nil. I can't see it ever being created in the code you provided.
Maybe you intended to present the Recipe photo controller as the content of the popover. In that case you would do something like
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
self.popover = [[UIPopoverController alloc] initWithContentViewController:recipePhotoViewController];
problem is in this line of your code ,
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
try like this
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 260)];
popoverContent.view = popoverView;
//Add what ever you want popoverView
self.popover = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
self.popover.delegate =self;
How to add the UIView into UIPopoverViewController
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
This will add the view to your UIPopoverViewController
You can check the following link below to get some idea as to how to do this
Are there examples of how to use UIPopoverController on iOS?
Try the below Code:
if (mycontroller == nil) {
MyController * viewController = [[MyController alloc] initWithNibName:#"ControllerView" bundle:nil];
mycontroller = viewController;
PopoverController = [[UIPopoverController alloc] initWithContentViewController:self.mycontroller];
PopoverController.delegate = self;
}
[PopoverController presentPopoverFromRect:CGRectMake(260, 120, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];