I am having a great deal of trouble displaying at small, live camera image in a viewController.
I would have expected the following code to show camera display to appear in a 100x 100 window, but it keeps appearing full screen!
Help appreciated.
camera = [[UIImagePickerController alloc] init];
UIView *cameraHUD = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
cameraHUD.userInteractionEnabled = YES;
[camera setSourceType:UIImagePickerControllerSourceTypeCamera];
camera.showsCameraControls = NO;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;
camera.cameraOverlayView = cameraHUD;
[self presentModalViewController:camera animated:YES];
[self.view bringSubviewToFront:cameraHUD];
You are present a new view instead of your actual view, so by default a new UIView has contentmode= scale to fill.
You have to add for example something like:
[camera setContentMode:UIViewContentModeTopLeft];
But if you want do something cool you have to add your Camera View as subview.
I hope it can help you
bye ;)
Related
I got a lot of problems implementing Game Center.
My game its based on Cocos2d But my Menu I do it with XIB. So the main window i make it like this:
UIWindow
UINavigationController
Navigation Bar
UIViewController [Menu]
UINavigationItem
When i click on Play I create a new View Controller called Menu2Game.h.m.xib And i add the OpenGL to this view, and then Menu2Game add it to my menu View
menu2Game = [[Menu2Game alloc] initWithNibName:#"Menu2Game" bundle:nil];
[menu2Game setView:glView];
[self.view addSubview: menu2Game.view];
I don't know why I can't add it directly... But when I click on leaderboards I do the same thing. Presenting the view directly on Menu doesn't work.
UIViewController *tempView = [[UIViewController alloc] init];
[self.view addSubview:tempView.view];
[[GameCenter sharedGameCenter] showLeaderboard:tempView];
And when I call my leaderbords its this code.
if ([self isGameCenterAvailable]) {
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil) {
screen = screen2;
leaderboardController.leaderboardDelegate = self;
[screen presentModalViewController: leaderboardController animated: YES];
[leaderboardController setCategory:#"015.1"];leaderboardController.view.frame.origin.y);
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);
}
}
The problem here its that doesn't respects the application Orientation
If its in Landscape. It start in 80, 320, And finish in 480, 320
It appears and you can use it but appears not in ----> this direction it moves like with 45 degrees
And if you hold the phone in Portrait [Any]. It appears only a small fragment of the leader boards, Facing the real orientation, but the coordinated are different it takes the ones you are holding. And in my plist its not permuted portrait.
How could i fix this? I got 1 week to finish this game and this is the only thing I miss.
Thanks to everybody
I don't know why but just create should rotate and return true.., and eliminate all the code that modify the game center
this one:
[leaderboardController setCategory:#"015.1"];leaderboardController.view.frame.origin.y);
leaderboardController.view.bounds = CGRectMake(0, 0, 480, 320);
leaderboardController.view.center = CGPointMake(240, 160);
}
My search bar is stretched slightly too far right when you start in landscape mode. It is still slightly too wide if you then rotate to portrait mode. However, its fine if you start in portrait mode and also if you then rotate it to landscape. Here is my code.
sBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
[sBar sizeToFit];
sBar.delegate = self;
sBar.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin;
[self.view addSubview:sBar];
The answer was to add the search bar to the view before running the rest of the code.
UISearchBar * tempSBar = [[UISearchBar alloc] initWithFrame:CGRectZero];
self.sBar = tempSBar;
[tempSBar release];
[self.view addSubview:sBar];
[sBar sizeToFit];
sBar.delegate = self;
sBar.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleBottomMargin;
UIViewAutoresizingFlexibleRightMargin
add that to sBar.autoresizingMask, i have that aswell as the other 2 and have no issues. if you are using IB, make sure its the right width in there also
I know this is old and deprecated, but I just had to share. I looked high and low for a solution that would work for my case. I tried all the suggestions, to no avail. Then I stumbled across this gem
// Update search bar frame.
CGRect superviewFrame = self.searchDisplayController.searchBar.superview.frame;
superviewFrame.origin.y = 0.f;
self.searchDisplayController.searchBar.superview.frame = superviewFrame;
And everything became nice and sunny again. Thank you Peter at
http://petersteinberger.com/blog/2013/fixing-uisearchdisplaycontroller-on-ios-7/
I'm using an picker Controller with a cameraOverlayView to display an image of a product in the camera view. The product image is resized before applying on the overlay.
It works fine on iOS 4.2 but on iOS 4.3 the product image is displayed full size.
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];
// Resize
if(imgView.frame.size.height == 480)
{
//Portrait
imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
// Landscape
imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}
imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;
pickerController.cameraOverlayView = (UIView *) imgView;
I changed the frame of the UIImageView I use as overlay but it's still displayed at 320*480.
I know that the cameraOverlayView have been modified in iOS 4.3 but I don't know what has changed and what I have to do to correct my application.
Thanks for your help.
In iOS 4.3 the overlay view is stretched to full screen. Because you set the content mode to aspect fit, the image is stretched to fit the new view size which is 320x480.
You need to make a transparent UIView that is fullscreen, add the imageview to that view and make the UIView the new overlay view.
UIView *fullscreenView = [[UIView alloc] initWithFrame:CGRectZero];
fullscreenView.backgroundColor = [UIColor clearColor];
....
[fullscreenView addSubview:imgView];
pickerController.cameraOverlayView = fullscreenView;
Found this article that seems to fit the bill. The long and short of it is to use
- (UIImage *)
resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality;
Comment out this line in your code
imgView.clipsToBounds = NO;
It should work.
If you really want to clip, #slf 's answer should help.
try setting these properties of UIImagePicker:
mImagePickerController.showsCameraControls = NO;
mImagePickerController.navigationBarHidden = YES;
mImagePickerController.toolbarHidden = YES;
mImagePickerController.wantsFullScreenLayout = YES;
My problem was actually that a UIImagePicker displayed full-screen on iOS5 did not work on iOS4.3, on an iPad. I was starting the image picker up offscreen, then animating it into view... You would see the shutter image open up, but then the camera view itself was simply transparent with no camera output.
My solution was to not animate that in for iOS4.3 on the iPad. It seems that having the camera view started offscreen was leaving the camera rendering part behind (fixed as I noted in iOS5).
This answer is not quite right for the original question but I place it here for someone that comes into the same issue and hits this question as I did.
I'm developing an app that needs to take two pictures in a row. I'm currently using the iPhone camera but :
I would like to NOT have the cancel
button on the bottom left
I would like to NOT have the preview of my picture (with the blue
button "use").
What should I do ? Should I make my own camera ? I couldn't find an easy tutorial for a custom camera with only a "take picture" button...
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];
The easiest way to do it is to use UIImagePickerController with showsCameraControls set to NO and a custom view set in cameraOverlayView; this view can have whatever buttons you need on it. When touched, the button should call takePicture on the image picker, and when you're done just use dismissModalViewControllerAnimated: to dismiss the picker.
How can I set correct orientation of MPMediaPickerController ?
I've return YES in shouldAutorotateToInterfaceOrientation, but i have bad frame for Landscape (if show MPMediaPickerController in Portrait first, and conversely).
I've rotating my device chaotically and sometime frame set to correct himself!
I've find the method to set frame by rotating - need rotate to 180 degreess.
For example, if you have good frame in Portrait, when you rotate to Landscape - you have bad frame (from Portatait), but if you rotate to other landscape (to 180 degreess), then frame set to Landscape...
Why ?
How can i set the frame after rotation correct always ?
regards,
Not sure whether you are interested in the solution or not, since you asked this in 2010.
Anyway, after a few searches here is what I found:
MPMediaPickerController DOES NOT SUPPORT LANDSCAPE ORIENTATION.
In order to make the MPMediaPicker appear nicely in landscape orientation, we can make use of PopOverController. Basically, we create a pop over, and insert the picker into it. PopOverController, when displayed properly from the rootViewController, will indeed follow the orientation of the device.
Here is the rough code. It works, but needs some cleaning up. Probably best you check whether
the popover is nil or not, otherwise it will just stack up on itself each time the user tap on the button.
- (IBAction)showMediaPicker:(id)sender
{
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES;
mediaPicker.prompt = #"Select musics...";
UIPopoverController *colorPickerPopover = [[[UIPopoverController alloc]
initWithContentViewController:mediaPicker] retain];
[colorPickerPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
A little more note: this IBAction is tied to a Toolbar Bar button.
I'm simply pushing it onto my navigation controller:
MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAny];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = NO;
mediaPicker.prompt = #"Select songs...";
[[self navigationController] pushViewController:mediaPicker animated:YES];
Granted this only works in the context of a navigation controller, but it works and is simple!
here is some sample code you can try it one , after rotation you have to set media palyer view in center of self.view, here some sample code... you have to add MediaPlayer Framework at first....
NSString* moviePath = [[NSBundle mainBundle] pathForResource:#"PATRON_LOGO_3" ofType:#"mp4"];
NSURL* movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *playerCtrl = [[MPMoviePlayerController alloc]initWithContentURL:movieURL];
playerCtrl.scalingMode = MPMovieScalingModeFill;
playerCtrl.controlStyle = MPMovieControlStyleNone;
[playerCtrl.view setCenter:CGPointMake(240, 160)];
[playerCtrl.view setTransform:CGAffineTransformMakeRotation(M_PI/2)];
playerCtrl.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:playerCtrl.view];
[playerCtrl play];
i think it works fine , this is for landscape mode for portrait we have to set frame according to portrait frame like..
playerCtrl.view.frame = CGRectMake(0, 0, 480, 320);
after that we have to set to center of view.