iPad2相机代码和iPhone4一样吗?

发布于 2024-10-29 04:19:16 字数 1503 浏览 4 评论 0原文

我正在为 iPad 制作一个应用程序,并且希望能够使用 iPad 2 摄像头(如果可用)。加载iPad相机的代码与iPhone 4的代码相同吗?我在这个应用程序的 iPhone 版本上运行了相同的代码,但没有 iPad 2 来测试,并且模拟器无法帮助我使用相机。下面是我必须确定相机是否可用,然后在弹出窗口中加载相机或加载库

基本上我只需要知道 iPad 2 相机是否支持下面的行,或者我需要使用其他东西吗?

[self presentModalViewController:imagePickerController animated:YES];

我希望相机是全屏而不是弹出窗口。

- (IBAction) takePhoto:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        imagePickerController = [[UIImagePickerController alloc] init];
        [imagePickerController setDelegate:self];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self presentModalViewController:imagePickerController animated:YES];
    } else { 
        imagePickerController = [[UIImagePickerController alloc] init];
        [imagePickerController setDelegate:self];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        [popover setDelegate:self]; 
        [popover presentPopoverFromBarButtonItem:sender 
                        permittedArrowDirections:UIPopoverArrowDirectionAny 
                                        animated:YES];
    }
}

I am making an app for the iPad and want to be able to use the iPad 2 camera if available. Is the code to load the iPad camera the same as for the iPhone 4? I have this same code working on the iPhone version of this app, but do not have an iPad 2 to test with and simulator can't help me with the camera. Below is what I have to determine if camera is available and then to load camera or load library in popup

Basically I just need to know if the line below is supported by the iPad 2 camera or do I need to use something else?

[self presentModalViewController:imagePickerController animated:YES];

I want camera to be full screen and not in a popup.

- (IBAction) takePhoto:(id)sender {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        imagePickerController = [[UIImagePickerController alloc] init];
        [imagePickerController setDelegate:self];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self presentModalViewController:imagePickerController animated:YES];
    } else { 
        imagePickerController = [[UIImagePickerController alloc] init];
        [imagePickerController setDelegate:self];
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
        [popover setDelegate:self]; 
        [popover presentPopoverFromBarButtonItem:sender 
                        permittedArrowDirections:UIPopoverArrowDirectionAny 
                                        animated:YES];
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘味果▽酱 2024-11-05 04:19:16

是的,如果 self 是 UINavigationController,那么这确实有效。我知道这一点是因为我在我的应用程序中也做了同样的事情。我不确定其他 UIViewControllers,但按理说它也能工作。

Yes this works, for sure if self is a UINavigationController. I know this because I do the same in my app. I'm not sure for other UIViewControllers, but it stands to reason that it will also work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文