I'm initializing an UIImagePickerController like this:
self.cameraController = [[UIImagePickerController alloc] init];
self.cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
self.cameraController.showsCameraControls = NO;
self.cameraController.navigationBarHidden = YES;
self.cameraController.wantsFullScreenLayout = YES;
The problem is that when this is shown, instead of the camera controls,
I get a black bar in its place.
How can I make UIImagePickerController.frame take all the screen space?
Thanks!
The iPhone's camera has a 4:3 aspect ratio whereas the iPhone's screen's aspect ratio is 3:2. Therefore, the live camera picture does not cover the entire screen. If you want to get rid of the black bars, you have to apply a small scaling transform (e.g. 110%) to the camera view.
Ole is spot on, figure out that aspect ratio conversion. Here is the line of code you are probably going to want to implement it.
self.cameraController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformIdentity, 2, 2);
Related
I have set an UIIMagePicker in my app with:
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.modalPresentationStyle = UIModalPresentationFullScreen;
imagePickerController.showsCameraControls = NO;
imagePickerController.navigationBarHidden = YES;
imagePickerController.toolbarHidden = YES;
imagePickerController.wantsFullScreenLayout = YES;
//imagePickerController.cameraViewTransform = CGAffineTransformScale(imagePickerController.cameraViewTransform, 1.0, 1.3);
imagePickerController.delegate = self.overlayView;
[self.view addSubview:imagePickerController.view];
imagePickerController.cameraOverlayView =self.overlayView.view;
All good and fine while the app is in portrait mode. Yet, if I rotate it in landscape a strange issue happen: a black bar appears on the right side and the view is 'rotated', in the sense that if I move the iPhone upward the image moves to the side and viceversa.
If I start in landscape mode, the black bar does not appear (it conversely shows when I rotate to portrait mode on the bottom), but the funny rotating behavior happens all the same.
In both cases the overlay screen seems to fill the screen and also correctly handle rotation.
What might be the issue and how to fix it?
Thanks, Fabrizio
I am facing gesture issue which is occurred only in iOS 7. I am adding UIPinchGestureRecognizer on UITextView like this :
pinchGestRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(scaleTextViews:)];
pinchGestRecognizer.delegate = self;
[multipleTextView addGestureRecognizer:pinchGestRecognizer];
And in scaleTextViews: method I have written this code:
- (void)scaleTextViews:(UIPinchGestureRecognizer *)pinchGestRecognizer1
{
multipleTextView.transform = CGAffineTransformScale([multipleTextView transform], [pinchGestRecognizer1 scale], [pinchGestRecognizer1 scale]);
[pinchGestRecognizer1 setScale:1];
}
When I zoom in the textview in iOS 7 and give a color to the text then my textView getting cutoff and changed its position.
Please suggest me what to do.
Thanks in advance...
If I understood your problem correctly, you want to change the way a view (in your case a label) is scaled when pinched. You can achieve different scaling types by changing the view layers anchor point.
For your example:
multipleTextView.layer.anchorPoint = CGPointMake(1, 1);
You can play around with anchorPoint, to find the effect that you would like to get.
I have the below code in my app which displays a UIImagePicker minus the camera controls.
#define CAMERA_SCALAR 1.32
#implementation CameraViewController
- (id)init {
// Remove standard controls from UIImagePicker and make full screen
if (self = [super init]) {
self.sourceType = UIImagePickerControllerSourceTypeCamera;
self.showsCameraControls = NO;
self.navigationBarHidden = YES;
self.toolbarHidden = YES;
self.wantsFullScreenLayout = YES;
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, 1, CAMERA_SCALAR);
}
return self;
}
Initially when I removed set showsCameraControls to NO I got a black bar on the screen where the controls had been. To offset this I added in the self.cameraViewTransform line to scale up the view.
This works, however it distorts the image. I think what I need to do is also scale the height by the same ratio as the width.
Can anyone advise me on the best way to do this ?
Thanks in advance !
I may be misinterpreting your question, but to scale the width as well, you can
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, CAMERA_SCALAR, CAMERA_SCALAR);
instead of
self.cameraViewTransform = CGAffineTransformScale(self.cameraViewTransform, 1, CAMERA_SCALAR);
But of course, this will push the sides of the camera view out of screen.
In principle, I think there is no best choice in this case (showing exactly what the camera shows in fullscreen), because the origin of the problem is the difference of the aspect ratio of the screen/camera. You either have to miss part of the view, or distort the view, is my thinking.
I'm trying to layout several custom views in a landscape iPad application (made landscape by deleting all but one interface mention in the plist). However, my code currently doesn't work as expected;
- (void)viewDidLoad {
[super viewDidLoad];
LeftTableViewController *lvc = [[LeftTableViewController alloc] initWithNibName:#"LeftTableViewController" bundle:nil];
// Resize this view controller appropriately
lvc.view.frame = CGRectMake(0, 0, 224, 768);
[[self view] addSubview:lvc.view];
ReaderViewController *rvc = [[ReaderViewController alloc] initWithNibName:nil bundle:nil];
// Resize this view controller appropriately
rvc.view.frame = CGRectMake(224, 0, 800, 768);
[[self view] addSubview:rvc.view];</code>
I expected the code above to give me the LeftTableViewController entirely to the left. This appears to work, but I had to remove all the size markers from the nib to get it there. The ReaderViewController should take up the remaining space, but it only takes up about half of the space left. This image illustrates this (the ReaderViewController is the green space, while the application is the purple space).
http://i52.tinypic.com/z7d2.png
I seem to be misunderstanding something crucial about frames and bounds in landscape mode. What coordinates for the frame or bounds should I set for a view to appear as expected and why?
Coordinates are same for both landscape, portrait modes. Portrait is 0,0 (left, top) and 768,1024 (width, height) and 0,0 (left, top) and 1024,768 (width, height) for landscape.
It's quite hard to answer, because we don't see the whole code and your XIB file. You have wrong autoresizing mask probably.
P.S. 768 is not correct height, because you have status bar visible, which has 20 pixels.
I have an simple UIImagePickerController where I hide the camera controls and set the sourceType to the camera. This opens the live camera preview right away but there's about a 50px hight black bar at the bottom of the viewer. Any idea how to get rid of this?
Thanks Usman for the link. The ratio seems to be a bit different from what's suggested in the blog. The ratio of 1.23 works for iPhone 4 and 4s. Also, in order to preserve the aspect ratio, I suggest scaling both x and y.
picker = [[UIImagePickerController alloc] init];
picker.sourceType = sourceType;
picker.delegate = self;
picker.allowsEditing = NO;
picker.showsCameraControls = NO;
CGAffineTransform cameraTransform = CGAffineTransformMakeScale(1.23, 1.23);
picker.cameraViewTransform = cameraTransform;
I believe this is due to the differing aspect ratio of the camera vs. the iPhone screen.