UIPopoverController And UIImagePickerController problems with Monotouch - ipad

I use to develop an application MonoTouch Iphone, but I have a problem using UIPopoverController. I can not open the page to select the photo.
I use the class of camera.cs TweetStation.
Here's the code:
public static void SelectPicture (UIViewController parent, Action<NSDictionary> callback)
{
if(OzytisUtils.isIpad()){
picker = new UIImagePickerController();
UIPopoverController popover = new UIPopoverController(picker);
picker.Delegate = new CameraDelegate();
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
popover.SetPopoverContentSize(new SizeF(parent.View.Frame.Width,parent.View.Frame.Height),true);
if(popover.PopoverVisible){
popover.Dismiss(true);
picker.Dispose();
popover.Dispose();
}else{
popover.PresentFromRect(parent.View.Frame,parent.View,UIPopoverArrowDirection.Right,true);
}
}else{
Init ();
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
_callback = callback;
parent.PresentModalViewController (picker, true);
}
Thanks for your help.

I have a few suggestions. First make the UIPopoverController a member variable so that it does not get collected.
Second I called ContentSizeForViewInPopover on the picker.
picker.ContentSizeForViewInPopover = new SizeF(this.View.Frame.Width,this.View.Frame.Height);
Finally I use a 0x0 rectangle in the upper left of the screen for the PresentFromRect call.
_popover.PresentFromRect(new RectangleF (0,0,0,0),this.View,UIPopoverArrowDirection.Up,true);

Related

How to get UIView in cocos2dx, Need to add UIImagePickr

I have made a bridge class for calling Objective-C functions in Cocos2d-X's cpp classes.
Now I have to show ImagePicker for capturing UserPhoto.
// Method from testBridge class, written in C++
TestBridge::captureImage(UIView*);
// Calling it from a class derived from CCLayer
// Here problem is how to get UIView,
// I can get CCEAGLView view = CCDirector::sharedDirector()->getOpenGLView();
// Don't know how to cast UIView from CCEAGLView
TestBridge::sharedInstance()->captureImage(view);
In the TestBridge class I call a objective C class's method captureImage
which has the following implementation
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = sourceType;
picker.wantsFullScreenLayout = YES;
[view addSubview:picker.view];
// I have also called presentViewController from picker, but it gives crash
I think I have conveyed my problem, Anyone knows anything about my problem?

ios7 CameraPickerController image from camera is frozen

I have this simple code for camera View controller:
UIImagePickerController picker = new UIImagePickerController();
picker.PrefersStatusBarHidden ();
picker.SourceType = UIImagePickerControllerSourceType.Camera;
UIImagePickerControllerCameraDevice dev = picker.CameraDevice;
PresentViewController (picker, false, null);
picker.FinishedPickingMedia += (object sender, UIImagePickerMediaPickedEventArgs e) => BeginInvokeOnMainThread (delegate {DismissViewController (false, null);});
When app starts, I can capture photo normally, but when i present picker again, camera View appears but frame(image) from previous shot is shown and frozen. If i move my device around image doesn't change. In other words, I can use camera once but I can not use it twice. What I am doing wrong? On iOS6 devices it works perfectly.
Making a pickerDelegate class did the trick for me. You just have to pass the current VC in the constructor so you can handle the image in your VC.
PickerDelegate
private class pickerDelegate : UIImagePickerControllerDelegate
{
private yourVC _vc;
public pickerDelegate (yourVC controller) : base ()
{
_vc = controller;
}
public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
{
//Do something whit the image
_vc.someButton.SetBackgroundImage (image, UIControlState.Normal);
//Dismiss the pickerVC
picker.DismissViewController (true, null);
}
}
ViewDidLoad
imagePicker = new UIImagePickerController ();
//Set the Delegate and pass the current VC
imagePicker.Delegate = new pickerDelegate (this);

UIImagePickerController not full screen

Since the iOS7 upgrade, I have a weird behaviour of the UIImagePickerController. In this application I am using the UIImagePickerController with a cameraOverlayView.
In iOS6 I called the UIImagePickerController using the following code:
_picker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
_picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
_picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
_picker.showsCameraControls = NO;
_picker.navigationBarHidden = NO;
_picker.toolbarHidden = YES;
_picker.wantsFullScreenLayout = YES;
_overlayViewController = [[OverlayViewController alloc] init];
_overlayViewController.picker = _picker;
_overlayViewController.frameSize = self.frameSize;
_overlayViewController.delegate = self;
_picker.cameraOverlayView = _overlayViewController.view;
}
else {
_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
_picker.delegate = self;
Where the OverlayViewController is an UIViewController, with a transparent background which draws some custom controls on screen.
But now in iOS 7 the camera is drawn through the statusbar and a black bar appears beneath the live camera view.
I can solve this by applying a CGAffineTransformMakeTranslation to the cameraViewTransform property of the UIImagePickerController, but why is this like this?
In iOS 7, by default UIViewController views take up the entire screen area including the status bar.
wantsFullScreenLayout
is deprecated and ignored. In some cases, this fix works (in the view controller class):
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
In other cases, it's a bit more complicated. It's late here, so see how you go with it. Helpful things to note - in a UIViewController, the following code will give the correct statusbar height on both iOS 6 and iOS 7, should it come to having to align things using CGRect math:
if (UIDeviceOrientationIsLandscape(self.interfaceOrientation)) {
statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.width;
} else {
statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
}
And then don't forget that in Interface Builder, there are the new "iOS 6 delta" adjustments that allow you to design for iOS 7 and then use offsets to correct for iOS 6.
Anyhow, let me know how you go.
My understanding of the issue, based on a few other SO threads and such, is that UIImagePickerController does not do what we'd expect in terms of managing the status bar via [UIViewController -prefersStatusBarHidden].
This means you either have to disable view controller status bar management entirely, via plist, or figure out a way to get UIImagePickerController to do what we want. On the assumption that you're not looking for the former, I can say I've had success in the latter by putting the picker in a wrapper controller that does what I want (but fall back to your previous code if you still need to detect/support iOS6):
#interface PickerContainer : UIViewController
#property ( nonatomic, weak ) UIImagePickerController* picker;
#end
#implementation PickerContainer
- (void) setPicker: (UIImagePickerController*) picker
{
[self addChildViewController: picker];
[picker didMoveToParentViewController: self];
self->_picker = picker;
}
- (void) viewDidLoad
{
[super viewDidLoad];
self.picker.view.frame = self.view.bounds;
[self.view addSubview: self.picker.view];
}
// Will have no effect in ios6 -- see [-init] for that option
- (BOOL) prefersStatusBarHidden { return YES; }
- (id) init
{
if ( ! ( self = [super init] ) ) return nil;
if ( detectThatThisIsIos6() ) self.wantsFullScreenLayout = YES;
return self;
}
#end
This will work for you, scaled camera, you will have a black bar at the bottom but it will get overlayed by tool bar
https://stackoverflow.com/a/15803947

Programmatically take X amount of pictures

I am trying to implement a feature of taking X amount of pictures programmatically after entering a UIViewController for both the iPhone and iPad. I looked into UIImagePickerController but I do not want to present the camera controls and have the user hit a button to capture only one photo. Is there a way to capture X amount of photos once entering a UIViewController and storing all the photos in the end for future reference in one go?
Edit:
-(void)viewDidAppear:(BOOL)animated
{
// Create image picker controller
picker = [[UIImagePickerController alloc] init];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
// Set source to the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Delegate is self
picker.delegate = self;
// Allow editing of image ?
picker.allowsEditing = NO;
//picker.showsCameraControls = NO;
// Show image picker
[picker animated:YES completion:nil];
}
straight away with takePicture you can not take multiple snaps, for that you have to use some video recording and get snap out of it for particular frame or time, for you more reference you can use this apple documentation for bulk snaps AVFoundation Programming Guide
You can try something like this:
int numberOfPhotos = 3; // Number of photos you want to take.
for ( int i = 0; i < numberOhPhotos; i++ )
{
// Note that you should use some sort of a pause in between each photo.
[picker takePicture];
}

Creating a utility method that generates a UIImagePickerController popup and returns the selected UIImage

What I want to do is create a Popup with a UIImagePickerController. This parts easy but I want to create a utility method that generates the UIImagePickerController popup and returns the UIImage once the user selects it. The problem is that the UIImagePickerController has a delegate property that is used for asynchronous completion. My thought was that maybe I could pass in a delegate to my utility function that contains the code to execute once the image is selected but the code to execute needs to operate on the image that was selected. This is the code I have so far and just so everyone knows, it crashes. I believe it's because I'm executing it in a static method.
namespace GalleryProto
{
static public class CameraUtility
{
public static void GetImageFromGalleryWithPopup(UIViewController parentViewController, PointF centerPoint)
{
UIImagePickerController imagePicker;
UIPopoverController popOver;
imagePicker = new UIImagePickerController ();
popOver = new UIPopoverController (imagePicker);
popOver.DidDismiss += (popOverController, e) =>
{
if (popOver != null && popOver.PopoverVisible) {
Console.WriteLine ("Popover Dismissed.");
popOver.Dismiss (true);
imagePicker.Dispose ();
popOver.Dispose ();
imagePicker = null;
popOver = null;
}
};
Console.WriteLine ("Before Finished Picking Image Delegate.");
imagePicker.Delegate = new MyPickerDelegate (imagePicker, popOver);
imagePicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
imagePicker.AllowsEditing = false;
imagePicker.MediaTypes = new string[] {"public.image"};
RectangleF popRectangle = new RectangleF (centerPoint, new SizeF (1, 1));
popOver.PresentFromRect (popRectangle, parentViewController.View, 0, true); //Center the popup on the Image Content View.
}
public class MyPickerDelegate : UIImagePickerControllerDelegate
{
UIImagePickerController _imagePicker;
UIPopoverController _popOver;
public MyPickerDelegate(UIImagePickerController imagePicker, UIPopoverController popOver)
{
_imagePicker = imagePicker;
_popOver = popOver;
}
public override void Canceled (UIImagePickerController picker)
{
Console.WriteLine("Canceleled");
}
public override void FinishedPickingImage (UIImagePickerController picker, UIImage image, NSDictionary editingInfo)
{
Console.WriteLine("Finished Picking Image");
_popOver.Dismiss (true);
_imagePicker.Dispose ();
_popOver.Dispose ();
_imagePicker = null;
_popOver = null;
}
}
}
}
I solved my issue by passing in a delegate for the callback that takes a UIImage as an argument so that the image can be manipulated appropriately once it's selected.

Resources