I'm making a pop over presentation view controller where I need to use multiple arrow directions (up and down). For having multiple permittedArrowDirections I've followed Set Multiple Arrow Directions on UIPopoverController in Swift. Also I tweaked the background color of the pop over so that the arrow blends in with the background dimming view.
The problem is, I need to prefer the UIPopoverArrowDirection.up for almost all cases but for the cases where there is not enough space in right below the source view only then the UIPopoverArrowDirection.down should be used. But I can't find to figure it out. The code snippet is:
let presentationController = .....
presentationController.sourceView = sourceView
presentationController.sourceRect = sourceView.bounds
// changing the array order doesn't help
presentationController.permittedArrowDirections = [.up, .down]
presentationController.backgroundColor = UIColor(white: 0, alpha: 0)
self.present(controller, animated: true)
For making it clear I'm attaching the current output:
The source for the demo that I've tried can be found here if anyone needs to follow along.
I am trying to have my application take a photo of an "intruder" when the wrong pin is entered into my application.
I have set up the UIImagePickerController(Below) and can make the application display the camera and take photos with no problem what so ever.
picker = UIImagePickerController() //make a clean controller
picker.delegate = self
picker.allowsEditing = false
picker.sourceType = UIImagePickerControllerSourceType.Camera
picker.cameraCaptureMode = .Photo
presentViewController(picker,animated: true,completion: nil)
Then i proceed to attempt this as to make the new set up for the picker
picker.showsCameraControls = false
I know that has to be set to false to call picker.takePicture()
Now I dont want to present the picker viewController and be able to call takePicture() but this is not hitting the delegate method of didFinishPickingMediaWithInfo.
I have tried using a custom overlay as well, but to no avail of 100% hiding the camera.
How do I go about not showing or displaying the camera on screen and being able to grab this picture of the front camera?
I have permission for access as well.
The other question posted on here of a similar topic does not solve this issue for help in swift.
Is the only way possible using AVFoundation?
If so, any help would be appreciated
I'm trying to display a video when my game ends (after a few minutes).
Here are the requirements :
The video is presented modally. Once it ends, it stays still on the last picture and the game can only be restarted by relaunching the app (this behavior is wanted)
The video does not have any control (no pause, no "Done" button etc.)
Most importantly : It does not occupy the whole screen. I want for example to display it in the middle of the screen, approximatively at 50% of the main screen size. (I need to see the VC underneath with a gray/transparent effect)
I achieved this using MPMoviePlayerController, but I did not notice that it was deprecated. So I'm now using AVPlayerViewController (added directly on storyboard)
This way I can :
Present it modally (using segue)
Set a grey/transparent background so that I can see the VC underneath
Disable the controls
But I CAN'T prevent it from resizing my video (I bet because videoGravity resizes it)
Here is my code :
// Game over
case GameSegue.GameEndSegue.rawValue:
// Get photo VC
let videoVC = segue.destinationViewController as! AVPlayerViewController
videoVC.modalTransitionStyle = .CrossDissolve
// Remove controls on the video
videoVC.showsPlaybackControls = false
// Get video URL and provide it to the player
let videoURL = helperClass.urlForFile(videoName)
videoVC.player = AVPlayer(URL: videoURL!)
videoVC.view.backgroundColor = UIColor(red: 0.5, green: 0.5, blue: 0.5, alpha: 0.6)
// This doesn't change anything (hard coded for example)
videoVC.view.frame = CGRectMake(0, 0, 300, 300)
// Play video
videoVC.player?.play()
Can someone please help on this ?
I'm trying to present a camera on the only the top half of my screen and my code isn't resizing the camera properly. I'm trying to add a view to the top half of my screen and then have the camera's cameraOverlayView property conform to that view's frame. Regardless of what I try however, the camera still appears in full screen mode. If someone can tell me what I'm doing wrong I'd really appreciate it. Thanks!
// Setting Up The Camera View
cameraView = UIView(frame: CGRectMake(0.0, 0.0, view.bounds.width, view.bounds.width))
view.addSubview(cameraView)
// Setting Up The Camera
var cam = UIImagePickerController()
cam.delegate = self
cam.allowsEditing = false
cam.videoMaximumDuration = 7
cam.videoQuality = UIImagePickerControllerQualityType.TypeMedium
cam.mediaTypes = UIImagePickerController.availableMediaTypesForSourceType(UIImagePickerControllerSourceType.Camera)!
cam.sourceType = UIImagePickerControllerSourceType.Camera
cam.cameraDevice = UIImagePickerControllerCameraDevice.Rear
cam.cameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video
cam.cameraFlashMode = UIImagePickerControllerCameraFlashMode.Off
cam.showsCameraControls = true
cam.cameraOverlayView = cameraView
cam.cameraOverlayView?.frame = cameraView.frame
camera = cam
self.presentViewController(camera, animated: false, completion: nil)
I do not think what you want to do can be accomplished using a UIImagePickerController. The AVFoundation is what you want to use if you want complete customization of the camera. You can read about it here https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html#//apple_ref/doc/uid/TP40010188-CH5-SW2.
P.S. It is not the simplest framework to use
My Application uses camera, I would like to add overlay over the camera preview. For example, I want to use a picture frame when I use Camera, also I would like to add a custom bar for camera operations. Kindly help me to do the same.
You might be trying using UIImagePickerController. But I know this one solution to your problem. You can do it easily using AVCamCaptureManager and AVCamRecorder classes. Apple has a demo program build on its developer site here. It is named AVCam. In simple words what it does is when you click to open the camera, it calls the classes and methods which are responsible for opening the iPhone's camera and record video or capture audio. It calls the same classes which are called by UIImagePickerController. So your camera will open and start taking input.
Now, if you open the xib file of that AVCam project, you'll find a small UIView object. This view is responsible for displaying the camera's feed. You can resize that view as per the size you want and the camera's input will be displayed in that much area. You can also put the frame image around it as per your choice.
It worked for me when I wanted to resize the camera's input feed and capture photos. I hope it works for you as well.
Create a UIImagePickerController from code, adjust its properties, add an overlay onto it, and with you controller, control whatever you want on that overlay : custom controls, overlaying images, etc...
That gives something like this :
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = YES;
// Insert the overlay
self.overlay = [[OverlayViewController alloc] initWithNibName:#"Overlay" bundle:nil];
self.overlay.pickerReference = self.picker;
self.picker.cameraOverlayView = self.overlay.view;
self.picker.delegate = self.overlay;
[self presentModalViewController:self.picker animated:NO];
OverlayViewController is the controller that you must write to control everything you add onto the overlay.
pickerReference is a property you can keep to send orders to the camera. For example, you could call the following from an IBAction coming from a UIButton placed onto the overlay :
[self.pickerReference takePicture];
Read the UIImagePickerController Class Reference, that's right in the documentation…
There are properties for this, especially the cameraOverlayView and showsCameraControls properties.
So you can hide the controls, provide a custom overlay view, and add subviews to this custom view to add custom buttons, frames, etc.
Swift 3 version for answer from Oliver:
self.picker = UIImagePickerController()
self.picker.sourceType = .camera
self.picker.cameraCaptureMode = .photo
self.picker.cameraDevice = .rear
self.picker.showsCameraControls = false
self.picker.isNavigationBarHidden = true
self.picker.isToolbarHidden = true
// Insert the overlay
self.overlayViewController = self.storyboard?.instantiateViewController(withIdentifier: "Overlay") as! OverlayViewController
self.picker.cameraOverlayView = self.overlayViewController.view
self.picker.delegate = self.overlayViewController
self.navigationController?.present(self.picker, animated: true, completion: nil)
OverlayViewController protocols:
class OverlayViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate