草庐IT

iphone - 横向的 UIImagePickerController

coder 2024-01-13 原文

我希望 UIImagePickerController 在横向代码中启动(并停留)。我尝试了此处描述的解决方案 (UIImagePickerController in Landscape)

//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];

方法didRotate:

- (void) didRotate:(NSNotification *)notification
{
      //Maintain the camera in Landscape orientation
 [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

}

但该解决方案不适用于 iOS 4.0。在 iOS 4.0 中启动相机时,应用程序没有响应。谁能建议解决这个问题?

最佳答案

您可以使用 ALAssetsLibrary 和 asset class 获取设备中的图片,您可以像 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 ];
}

关于iphone - 横向的 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3572263/

有关iphone - 横向的 UIImagePickerController的更多相关文章

  1. ruby-on-rails - Rails 3 和 PDFKit,如何将 HTML 文件转换为横向 PDF? - 2

    我可以很好地将HTML页面转换为PDF文档。问题是,我不知道如何将HTML文件转换为横向PDF。有没有办法在Controller中设置它?从Controller...defpdf_customer_shipments@customer=Customer.find(params[:id])@shipments=Shipment.where("customer_id=?ANDstatus='Open'",@customer.id)render:layout=>'pdf'end 最佳答案 如果这有帮助,我正在使用PDFKit,并且可以使用

  2. iphone - 扩展 restful_authentication/AuthLogic 以支持匿名 iPhone 的延迟登录的最佳方法是什么? - 2

    我正在构建一个与RubyonRails后端对话的iPhone应用程序。RubyonRails应用程序还将为Web用户提供服务。restful_authentication插件是提供快速和可定制的用户身份验证的绝佳方式。但是,我希望iPhone应用程序的用户在新列中存储一个由手机的唯一标识符([[UIDevicedevice]uniqueIdentifier])自动创建的帐户。稍后,当用户准备好创建用户名/密码时,帐户将更新为包含用户名和密码,iPhone唯一标识符保持不变。用户在设置用户名/密码之前不能访问该网站。然而,他们可以使用iPhone应用程序,因为该应用程序可以使用它的标识符

  3. iphone - 设计和 Rails 3 中的 http 身份验证 - 2

    我有一个使用deviseonrails3的应用程序。我想启用http身份验证,以便我可以从iPhone应用程序向我的网络应用程序进行身份验证。如何从我的iPhone应用程序进行身份验证以进行设计?这安全吗?还是我应该进行不同的身份验证? 最佳答案 从设计的角度来看,您有3个选择:1)使用基本的http身份验证:您的iPhone应用程序有一个secretkey-这是在您的iPhone应用程序代码中烘焙的-用于对网络应用程序的每个请求进行身份验证。Google搜索:“设计基本的http身份验证”2)您可以通过在您的iPhone应用程序中

  4. iphone - 在没有 Mac 的情况下开发 iPhone 应用程序? - 2

    这个问题在这里已经有了答案:关闭13年前。PossibleDuplicates:HowcanIdevelopforiPhoneusingaWindowsdevelopmentmachine?我想为我妻子的手机构建一个iPhone应用程序,但我对购买Mac作为一次性工作的开发平台不感兴趣。应用程序:应该在iPhone上独立运行(即没有网络连接)完全可以接受使用iPhoneJavascript库之一创建的GUI会做一些数据库IO来读取和更新数据没有商业值(value),永远不会被任何人使用这是我的想法:越狱iPhone在iPhone上安装Ruby+Sinatra使用Sinatra编写应用程

  5. iphone - iPhone 原生应用的测试驱动设计 - 2

    我正在试验iPhoneSDK并在Nic博士的rbiPhoneTest项目中做一些TDD。我想知道有多少人(如果有的话)成功地使用了这个或任何其他iPhone/Cocoa测试框架?更重要的是,我想知道如何最好地断言专有的二进制请求/响应协议(protocol)。这个想法是通过网络发送二进制请求并接收二进制响应。请求和响应是使用byteand'ing和or'ing创建的。我正在使用黄金副本模式来测试我的请求。这是我到目前为止所拥有的。不要笑,因为我是ObjectiveC和Ruby的新手:requireFile.dirname(__FILE__)+'/test_helper'require'

  6. iphone - 如何从视频中提取方向信息? - 2

    在网络上浏览了大量文档后,iPhone似乎总是以480x360的纵横比拍摄视频,并在视频rails上应用变换矩阵。(480x360可能会改变,但对于给定设备而言始终相同)这是一种在iOS项目中修改ffmpeg源代码并访问矩阵http://www.seqoy.com/correct-orientation-for-iphone-recorded-movies-with-ffmpeg/的方法这是在iOS-4中查找转换矩阵的更清晰的方法Howtodetect(iPhoneSDK)ifavideofilewasrecordedinportraitorientation,orlandscape.

  7. javascript - 是否允许将javascript代码下载到iPhone - 2

    我有一个混合应用程序,它基本上是一个从UIWebview内的应用程序文件夹运行的网站。问题是我打算通过从互联网下载整个网站然后替换旧网站来更新我的网站。今天发现苹果现在提供了AppStoreReviewGuidelines等规则:2.7Appsthatdownloadcodeinanywayorformwillberejected2.8Appsthatinstallorlaunchotherexecutablecodewillberejected因为我的网站有html、css和javascript,这是否意味着我的应用程序将被拒绝或有机会被接受?你对此有何看法?

  8. javascript - 拖动以像在 iPhone 中一样使用 jQuery 更改图像幻灯片 - 2

    我正在为我的站点使用超大型jquery插件。它带有下一张和上一张幻灯片的按钮。我想在其中实现拖动更改功能。如果有人点击并将鼠标向右移动,它应该充当下一张幻灯片按钮。但是我如何使用jquery来实现呢?我怎么知道用户何时单击n向左/向右拖动http://buildinternet.com/project/supersized/ 最佳答案 jQuery将mouseUp、mouseDown和mouseMove识别为事件。您必须在mouseDown上捕获鼠标位置,在它移动时更新位置并将其与您最初捕获的位置进行比较。虽然这是高度理论化的,但请

  9. javascript - 我可以使用 jquery 确定设备是纵向模式还是横向模式吗? - 2

    我想根据用于查看网站的设备是纵向/垂直还是横向/水平模式/方向,有条件地更改用户在我要创建的照片库网站上看到的内容。这可能吗? 最佳答案 尝试使用orientationchange事件处理程序,如下所示:$(window).bind("orientationchange",function(evt){alert(evt.orientation);});这是jQueryMobileentry检测并触发orientationchange事件。 关于javascript-我可以使用jquery

  10. javascript - iPhone 为 (hash and 3) 和 (Asterisk and 8) 返回相同的按键事件 - 2

    我正在处理电话验证,需要使用电话号码自动格式化输入,并且只允许添加数字字符。但是,当我尝试使用keydown和keypress限制输入时,iPhone允许我输入#和*。当我检查keydown值时,它们分别与3和8相同(键码51和56)。这在Android浏览器中完美运行,但在iPhone中失败。任何人都遇到过类似的问题。$(formSelector+'input[name^="phone"]').on('keydownkeypress',function(e){//Allow:backspace,delete,tab,escape,andenterif(e.keyCode==46||e

随机推荐