根据IOS文档说明,**The UIImagePickerController class supports portrait mode only**,就是UIImagePickerController
类只能支持竖屏模式,有没有什么方法能让横屏显示?
UIImagePickerController只支持竖屏模式
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答
- gaoXxxing 2013-01-07 07:55关注
可以用ALAssetsLibrary 获取设备中的图片,然后像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 ]; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥30 python代码,帮调试
- ¥15 #MATLAB仿真#车辆换道路径规划
- ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
- ¥15 数据可视化Python
- ¥15 要给毕业设计添加扫码登录的功能!!有偿
- ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
- ¥15 微信公众号自制会员卡没有收款渠道啊
- ¥100 Jenkins自动化部署—悬赏100元
- ¥15 关于#python#的问题:求帮写python代码
- ¥20 MATLAB画图图形出现上下震荡的线条