I am using navigation based application here when i call UIImagePicker then it show blank when the screen is in landscape but this shows correctly when the screen in portrait.
How can i change screen to portrait when its in landscape.
I using the code to call photo album is
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
Edited:
Actually i am using TabBarController Which was pushed from another view using the concept of navigationController then when i tried to call UIImagePickerController when it is in landscape then shows blank.
But without TabBarController UIImagePickerController works perfect(Automatically rotate to portrait)..
So how could i call UIImagePickerController when in landscape in TabBarController.
Thanks..
If this happens in a UIViewController then do the following so that the view is never rotated:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return NO;
}
if u want to forcefully rotate in portrait use
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation==UIInterfaceOrientationPortrait||UIInterfaceOrientationPortraitUpsideDown)
}
UIImagePickerController is portrait-only, see the documentation:
Important: The UIImagePickerController class supports portrait
mode only. This class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified [...]
Related
Hi I'm using following code to show my app's login screen.
LoginViewController * loginController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:loginController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self.navigationController presentModalViewController:navController animated:YES];
Its loading properly. Here my problem is my app should be in landscape mode only. Here I'm using UIModalPresentationFormSheet so app is automatically appearing in portrait mode. I would like to force my app to change to landscape mode after this login view loads. some one please help me how to rotate my view into landscape mode after this UIModalPresentationFormSheet loads. (It means in LoginViewController's viewDidLoad mode I have to force my app to change to landscape mode. How can I achieve that). Thanks in advance
Try re-writing your User Interface Frame attributes with landscape co-ordinate values.
Do this in
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
and with the proviso
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
I'm trying to only support landscape. There's a new requirement to show this dialog box that explains some things about our app the first time. So in my first view controller that gets launched, in viewDidLoad, I have this code:
BOOL showFirstTimeUse = [[NSUserDefaults standardUserDefaults] boolForKey:#"ShowFirstTimeUse"];
if (!showFirstTimeUse) {
FirstUseViewController *tvc = [[FirstUseViewController alloc] initWithNibName:#"FirstUseViewController" bundle:nil];
tvc.modalPresentationStyle = UIModalPresentationFormSheet;
tvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:tvc animated:YES];
[tvc release];
}
Then in the FirstUseViewController, I have this defined:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
In IB, I have not changed any of the default settings. I basically just dropped a UIWebView to the upper left hand side of the screen to show my data and connected an outlet to it so I can show formatted text easily.
When I run my app now, the presentation of this view controller causes my app to start in portrait rather than landscape. How do I fix this? Thanks.
Your implementation of shouldAutorotateToInterfaceOrientation: is faulty; It will always evaluate true. You likely want to use:
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
I am new to Iphone development. I am working on an application which involves two views. I have a camera button in view one which opens up the default Iphone camera. This is achieved by having this code in the IBAction for camera button in ViewOneController:
UIImagePickerController *picker =
[[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
[picker release];
The view controller for the first view is also the UIImagePickerControllerDelegate for the camera. When the picture is clicked and the camera view returns to the function imagePickerController:didFinishPickingWithMediaInfo where I do this:
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
[self presentModalViewController:ViewTwoViewController animated:YES];
}
So basically all I am trying to achieve is from viewone click "take picture" ---> Open camera --> after camera is done jump to view two. Quite simmilar to what it is in the flickr app. However after I take the picture from camera my app returns to view one and view two is not shown. What am I missing here?
Also from a conceptual perspective I guess IOS keeps a stack of views for any app. When presentModalViewController is called the view is shown and it is added to the stack and when dismissModalViewController is called the view is removed from the stack and the parent view is show. Is that right?
Thanks.
You probably need to put the call to [self presentModalViewController:ViewTwoViewController animated:YES] in viewWillAppear which will be called after the picker view has been removed.
You probably also need to surround the call with some check to only present viewTwo when applicable.
I have a segment controller on one of my views and now on the 0th index of segment controller I want to add UIImagePickerController (for showing camera view to user) by adding as sub view and not by ModalViewController. Right now the view gets loaded but It does not show any camera view. I am able to show the camera view by presentModalViewController and passing its object.
Here's the code--
if(segmentedControl.selectedSegmentIndex==0)
{
UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];
cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraView.showsCameraControls = NO;
//[self presentModalViewController:cameraView animated:YES]; //Working
[self.view addSubview:cameraView.view]; // Not Working
}
[self.view addSubview:picker.view];
[picker viewWillAppear:YES]; // trickery to make it show
[picker viewDidAppear:YES];
You get a white bar at the top as side effect since UIImagePickerController is not intended to be used with it.
You should avoid doing this, it is not recommended and could lead to unwanted side effects.
As stated on the documentation (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImagePickerController_Class) you cannot add it as a subview, you should present it as a new controller
Here a piece of the doc:
On iPhone or iPod touch, do this modally (full-screen) by calling the
presentViewController:animated:completion: method of the currently
active view controller, passing your configured image picker
controller as the new view controller.
Hope this helpes!
I am using TabBarController in my application. In one of the view of the tabbar I am using a UIImagePickerController to pick an image.
When I add the picker as follows
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.editing = YES;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
It adds the picker, But at the time of choosing the photo, The bottom bar having the buttons "choose" and "cancel" gets hide under my tabbar. How to resolve this .
The problem is that you are using self as the navigation controller that shows the modal screen. Therefore the tab bar navigation controller does not know that a modal screen should fill the whole screen. Since the UIImagePickerController can not adjust itself to a smaller size you have to use the tab bar navigation controller to open present the modal view.
I use the following code to show a UIImagePickerController from a navigation controller that is shown inside a tabbar:
[self.navigationController presentModalViewController:picker animated:YES];
using self.navigationController instead of self as the object that presents the UIImagePickerController did the trick for me.
This works for me:
picker.delegate = currentClassViewController;
[tabBarController presentModalViewController:picker animated:YES];
Have your picker-caller class own or have access to your UITabController variable and presentModalViewController against your tabBarController.
I haven't seen this problem - I have an app that uses a UITabBar and a UIImagePickerController together, and the tab bar does not obscure the image picker.
Inside my view controller, which is one of the UITabBar's view controllers, I'm creating the image picker as such:
self.imagePicker = [[[UIImagePickerController alloc] init] autorelease];
imagePicker.allowsImageEditing = NO;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
Seems very similar to your code, except that I'm setting the image picker as a retained property. Is your tab bar set up correctly? Is the view controller contained within the myTabBar.viewControllers array?