La documentation iOS indique "La classe UIImagePickerController
ne prend en charge que le mode portrait". Des alternatives à cela si je veux afficher la photothèque en mode paysage?UIImagePickerController prend en charge le mode portrait uniquement. Toutes les alternatives qui prennent en charge le mode paysage?
Répondre
peut-être cela vous aider .Vous pouvez utiliser la classe ALAssetsLibrary et atout pour obtenir les images dans votre appareil et vous pouvez les utiliser pour afficher en mode paysage et en mode portrait même comme uiimagepicker.
- (void)viewDidLoad
{
[super viewDidLoad];
[activity startAnimating];
appObj=(ImagePickerAppDelegate *)[[UIApplication sharedApplication]delegate];
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result != NULL)
{
//assets is a mutualable array...for storing the images that are in the device..
[assets addObject:result];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock:assetEnumerator];
}
//meth is a user defined method..
[self meth];
[activity stopAnimating];
[activity setHidden:YES];
};
assets = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAlbum usingBlock:assetGroupEnumerator
failureBlock: ^(NSError *error) { NSLog(@"Failure");}];
}
-(void)meth
{
NSLog(@"%i",[assets count]);
if(userOrientation==UIInterfaceOrientationPortrait || userOrientation==UIInterfaceOrientationPortraitUpsideDown)
{
NSLog(@"haii");
[scrollView removeFromSuperview];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor=[UIColor whiteColor];
NSLog(@"%i",[assets count]);
for (int i = 0; i < [assets count]; i++)
{
imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[imgBtn setFrame:CGRectMake((i%4*80)+2,(i/4*80)+2,75,75)];
imgBtn.tag=i;
[imgBtn addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
ALAsset *asset=[assets objectAtIndex:i];
[imgBtn setImage:[UIImage imageWithCGImage:[asset thumbnail]] forState:UIControlStateNormal];
[scrollView addSubview:imgBtn];
}
scrollView.contentSize = CGSizeMake(320,(([assets count]/4)+1)*300);
}
if(userOrientation==UIInterfaceOrientationLandscapeRight || userOrientation==UIInterfaceOrientationLandscapeLeft)
{
[scrollView removeFromSuperview];
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 480,320)];
for (int i = 0; i < [assets count]; i++)
{
imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[imgBtn setFrame:CGRectMake((i%6*80)+2,(i/6*80)+2,75,75)];
imgBtn.tag=i;
[imgBtn addTarget:self action:@selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
ALAsset *asset=[assets objectAtIndex:i];
[imgBtn setImage:[UIImage imageWithCGImage:[asset thumbnail]] forState:UIControlStateNormal];
[scrollView addSubview:imgBtn];
}
scrollView.contentSize = CGSizeMake(480,(([assets count]/4)+1)*300);
}
[self.view addSubview:scrollView];
}
-(void)imageClicked:(UIButton *)sender
{
//for picking the images that the user has selected we are using other array "selectedImages" i.e declared in the app delegate
ALAsset *asset=[assets objectAtIndex:sender.tag];
[appObj.selectedImages addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
NSLog(@"%i",[appObj.selectedImages count]);
[self.navigationController popViewControllerAnimated:YES ];
}
Ceci est une excellente solution, merci! – lichen19853
Je n'ai pas vérifié si c'est illégal, mais cela a fonctionné pour moi. Si vous voulez que le UIImagePickerController pour commencer (et rester) dans le code d'orientation paysage:
//Initialize picker
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
//Refer to the method didRotate:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
//Set the picker source as the camera
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//Bring in the picker view
[self presentModalViewController:picker animated:YES];
La méthode didRotate:
- (void) didRotate:(NSNotification *)notification
{
//Maintain the camera in Landscape orientation
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];
}
exact duplicate: http://stackoverflow.com/a/2147584/1106035 –
- 1. UIImagepickercontroller en mode paysage
- 2. mode paysage en tablette uniquement
- 3. UIView charge toujours en mode portrait
- 4. pushViewController: - comment afficher en mode portrait uniquement, quand l'appareil est en mode paysage?
- 5. Lancement de l'application en mode paysage uniquement
- 6. Comment afficher en mode paysage en mode portrait?
- 7. comment utiliser UIImagePickerController dans une application qui prend en charge l'orientation Paysage uniquement dans iOS-6?
- 8. Centrage d'Ipad en mode portrait, fonctionne en mode paysage
- 9. Transition entre le mode portrait et le mode paysage
- 10. Faux a Affichage en mode paysage en mode portrait
- 11. ADBannerView en mode paysage, mais pas en mode portrait
- 12. L'orientation est uniquement en mode paysage en mode cameraoverlay
- 13. iPad UIViewController se charge en portrait lorsque l'appareil est en mode paysage
- 14. Vue de l'iPad en mode paysage + portrait
- 15. Comment laisser l'application portrait en mode paysage
- 16. Comment vim prend-il en charge le mode C/S?
- 17. iPhone UIDatePicker en mode paysage?
- 18. Comment prendre en charge le mode paysage dans le tag vidéo uiwebview?
- 19. La barre d'état est en mode paysage après rotation en mode portrait uniquement
- 20. Utilisation du mode immersif uniquement en mode paysage
- 21. Le contenu iAd est toujours affiché en mode portrait à l'aide de l'application Paysage uniquement
- 22. Paysage Mode de portrait en Android
- 23. UIScrollView se comporte différemment en mode portrait et mode paysage
- 24. Le capteur d'accéléromètre conserve les mêmes paramètres en mode paysage que le mode portrait
- 25. Comment régler le mode portrait et paysage?
- 26. Mode paysage uniquement pour la vidéo
- 27. L'application iPad uniquement paysage affiche UIImagePicker en orientation portrait
- 28. Exécuter l'application en mode paysage uniquement?
- 29. qui prennent en charge Flash
- 30. Orientation portrait et mode paysage
C'est double de: bien mille questions – MCKapur
double possible de [UIImagePickerController en paysage] (http://stackoverflow.com/questions/2083672/uiimagepickercontroller-in-landscape) – jrturton
En fait, je pense que cette question est beaucoup mieux que les autres "doublons". Les autres questions ont été posées il y a un ou deux ans pour iOS 3 ou 4, et les gens ont discuté de beaucoup d'alternatives qui ne sont pas adaptées pour aujourd'hui; maintenant c'est iOS 6, il est donc préférable de revenir sur cette question et de rendre la situation plus claire et plus spécifique au dernier système d'exploitation. – lichen19853