UIImagePickerController presented inside view
Is that possible to present a UIImagePickerController inside a view, instead of using it modal or inside a popover?
I have tried this, without success...
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePi开发者_Python百科ckerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
NSArray *mediaTypesAllowed = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[picker setMediaTypes:mediaTypesAllowed];
picker.delegate = self;
[picker.view setFrame:CGRectMake(0,0, 400, 400)]; // just for testing
[picker.view setCenter:CGPointMake(200,200)];
[myView addSubview:picker.view];
[picker.view release];
}
thanks for any help
Can it be done legally?
Yes.
You can use the Image Picker outside of a popover/modal view, this isn't in itself illegal, it's just unsupported. Therefore it is fragile. You won't run into trouble with Apple for that when you submit your app but you will want to pay special attention whenever a new version of iOS comes out because it has the potential to break (because it's not supported to use the image picker in a different way).
I contacted Apple's Technical support about this since I am also needing to implement something similar to the iPad Pages.app popover with segmented control. Using the Image Picker as one of the segmented controls view contents.
I got everything set up and was working but I couldn't hide the Cancel button in the image picker. The Apple engineer told me it's not a supported solution and also told me Apple "has in the past have been known to use private APIs to achieve certain results". I don't think this is a huge surprise. But I am sure that today a least they do restrict themselves at least for their apps they publish in the App Store to use only public APIs.
Workaround
Please check out my git repo over on BitBucket, I got this working using view controller containment (which is available since iOS 5).
https://bitbucket.org/danielphillips/image-picker-demo
It also includes a bit of a hack to hide the cancel button. It does use an undocumented property, I'm not sure if you could called it a private API though, I've never before tried to hack Cocoa Touch's private APIs and I've never really been bothered about it either so I couldn't say if this is a light hack or if it's something Apple has software to detect I've used the private API.
So I don't know if the hiding of the Cancel button part will get you into the App Store or not, but it might be worth a try.
I strongly doubt it's possible without going outside the API.
The primary function of the picker view is to safely provide access to a system wide resource. In other words, it has a gatekeeper function that Apple doesn't want any app to be able to override. To enforce it's restrictions on access to the photolibrary at least, it has to be modal.
That might loosen up in 4.0 but I kind of doubt it.
Note: There is a minor exception to the "tapping outside a popover dismisses it" rule, which caused a problem in one of my app submissions. If you have a toolbar, tapping on the toolbar (which is technically outside the popover =) does not dismiss the popover. If you don't code for this case, it's possible to spawn two popovers at once, which will get your app rejected...
精彩评论