我无法隐藏我的应用程序的iphone相机快门打开动画。 我正在使用UIImagePickerController访问iphone相机并使用我自己的覆盖控制器。 有没有办法在相机启动时删除初始快门(也称为光圈)动画。 谢谢
[编辑]
对于那些想知道更改相机虹膜动画的方法的人。
在相机光圈动画开始之前调用以下功能。
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// Here is were I make the camera preview fit the entire screen.
// This might violate the "don't change the view hierarchy"-rule.
// So I am not sure if it is valid for App Store commitment.
// However, the NSLogs are used to
// figure out which subview is the actual Camera Preview which turns out
// to be the PLPreviewView. (uncomment to se the printouts).
// Change it's size to fit the entire screen (and scale it accordingly
// to avoid distorted image
NSLog(@"WillShowViewController called...");
NSLog(@"VC:view:subviews\n %@\n\n", [[viewController view] subviews]);
NSLog(@"VC:view:PLCameraView:subviews\n %@\n\n", [[[[viewController view] subviews] objectAtIndex: 0] subviews]);
NSLog(@"VC:view:PLCameraView:PLPreviewView:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 0] subviews]);
NSLog(@"VC:view:PLCameraView:PLCropOverLay:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 1] subviews]);
NSLog(@"VC:view:PLCameraView:UIImageView:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 2] subviews]);
}
在上面的函数中,你可以使用普通的NSMuatableArray语法来遍历每一层,比如objectAtIndex
希望这可以帮到你。
此致
ANKUR
答案 0 :(得分:5)
以this answer为出发点,我终于解决了这个问题:
注意:这显然不符合3.3.1。
在UINavigationControllerDidShowViewControllerNotification
和UIImagePickerController
全球范围内收听PLCameraViewIrisAnimationDidEndNotification
。
遍历视图层次结构(从主UIWindow
开始),寻找PLCameraView
。保存视图的索引对照主UIWindow
,稍后您将需要它。
从PLCameraView
移除superView
。如果需要,请在全局索引0处插入您自己的视图。
完成虹膜动画后,删除视图并在其原始索引处重新添加PLCameraView
。
答案 1 :(得分:1)
遇到类似的问题:当我拍摄由UIImagePickerController的self.cameraOverlayView中的按钮触发的图片时,我想要显示快门。到了这个页面,做了一些额外的研究,并找到了这个解决方案。
<强>梗概:强>
@interface MyController : UIImagePickerController
...
- (id) init {
...
self.cameraOverlayView = _my_overlay_;
self.showsCameraControls = NO;
...
}
...
- (void) onMyShutterButton {
[self takePicture];
// You want the shutter animation to happen now.
// .. but it does not.
}
<强>解决方案:强>
// Some constants for the iris view and selector
NSString* kIrisViewClassName = @"PLCameraIrisAnimationView";
SEL kIrisSelector = NSSelectorFromString(@"animateIrisOpen");
@implementation MyController {
...
UIView* iris_;
}
- (void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// Find the iris view in the siblings of your overlay view
for (UIView* view in self.cameraOverlayView.superview.subviews) {
if ([kIrisViewClassName isEqualToString:[[view class] description]]) {
// It will be hidden by 'self.showsCameraControls = NO'.
view.hidden = false;
// Extra precautions - as this is undocumented.
if ([view respondsToSelector:kIrisSelector]) {
iris_ = view;
}
break;
}
}
}
- (void) animateIrisOpen {
if (iris_) {
[iris_ performSelector:kIrisSelector];
}
}
...
- (void) onMyShutterButton {
[self takePicture];
[self animateIrisOpen]; // Voila - the shutter happens
}
答案 2 :(得分:0)
我已经搞砸了一下,但是将视图生命周期方法的各种组合发送到图像选择器。 (viewWillAppear,viewDidAppear等)但我不记得哪些人最终工作了。
答案 3 :(得分:0)
很抱歉回复这么晚才回来。我找到了那个井的解决方案,我玩了cameraView的视图层次结构,并在所有内容的顶部添加了我自己的图层。动画发生在那里,一旦快门打开,最顶层被移除。如果有人需要任何有关代码的进一步帮助,请告诉我,我将提供确切的步骤和语法。
-Ankur
答案 4 :(得分:0)
在相机光圈动画开始之前调用以下功能。
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
// Here is were I make the camera preview fit the entire screen.
// This might violate the "don't change the view hierarchy"-rule.
// So I am not sure if it is valid for App Store commitment.
// However, the NSLogs are used to
// figure out which subview is the actual Camera Preview which turns out
// to be the PLPreviewView. (uncomment to se the printouts).
// Change it's size to fit the entire screen (and scale it accordingly
// to avoid distorted image
NSLog(@"WillShowViewController called...");
NSLog(@"VC:view:subviews\n %@\n\n", [[viewController view] subviews]);
NSLog(@"VC:view:PLCameraView:subviews\n %@\n\n", [[[[viewController view] subviews] objectAtIndex: 0] subviews]);
NSLog(@"VC:view:PLCameraView:PLPreviewView:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 0] subviews]);
NSLog(@"VC:view:PLCameraView:PLCropOverLay:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 1] subviews]);
NSLog(@"VC:view:PLCameraView:UIImageView:subviews\n %@\n\n", [[[[[[viewController view] subviews] objectAtIndex: 0] subviews] objectAtIndex: 2] subviews]);
}
在上面的函数中,你可以使用普通的NSMuatableArray语法来遍历每一层,比如objectAtIndex
希望这可以帮到你。
此致
ANKUR
答案 5 :(得分:0)
joshwa的回答完全隐藏了虹膜动画持续时间的整个摄像机视图。为了我的目的,我需要相机视图可见,只是没有虹膜动画。我通过稍微调整一下他的方法就能完成这个任务。正如其他人所指出的那样,这可能会或可能不会在应用程序商店中被允许,因为我们正在弄乱视图层次结构以及监听未记录的通知。
需要3个ivars:
UIImagePickerController *imagePickerController;
UIView *plCameraIrisAnimationView; // view that animates the opening/closing of the iris
UIImageView *cameraIrisImageView; // static image of the closed iris
隐藏已关闭的虹膜图像并删除动画视图。我也尝试过隐藏动画视图,但动画仍然可见:
- (void)receivedNavigationControllerDidShowViewControllerNotification:(NSNotification *)notification {
UIView *view = imagePickerController.view;
[plCameraIrisAnimationView release];
plCameraIrisAnimationView = nil;
cameraIrisImageView = nil;
while (view.subviews.count && (view = [view.subviews objectAtIndex:0])) {
if ([[[view class] description] isEqualToString:@"PLCameraView"]) {
for (UIView *subview in view.subviews) {
if ([subview isKindOfClass:[UIImageView class]]) {
cameraIrisImageView = (UIImageView *)subview;
}
else if ([[[subview class] description] isEqualToString:@"PLCropOverlay"]) {
for (UIView *subsubview in subview.subviews) {
if ([[[subsubview class] description] isEqualToString:@"PLCameraIrisAnimationView"]) {
plCameraIrisAnimationView = [subsubview retain];
}
}
}
}
}
}
cameraIrisImageView.hidden = YES;
[plCameraIrisAnimationView removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"UINavigationControllerDidShowViewControllerNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedPLCameraViewIrisAnimationDidEndNotification:) name:@"PLCameraViewIrisAnimationDidEndNotification" object:nil];
}
动画结束后,取消隐藏虹膜图像并重新添加动画视图:
- (void)receivedPLCameraViewIrisAnimationDidEndNotification:(NSNotification *)notification {
cameraIrisImageView.hidden = NO;
UIView *view = imagePickerController.view;
while (view.subviews.count && (view = [view.subviews objectAtIndex:0])) {
if ([[[view class] description] isEqualToString:@"PLCameraView"]) {
for (UIView *subview in view.subviews) {
if ([[[subview class] description] isEqualToString:@"PLCropOverlay"]) {
[subview insertSubview:plCameraIrisAnimationView atIndex:1];
[plCameraIrisAnimationView release];
plCameraIrisAnimationView = nil;
break;
}
}
}
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PLCameraViewIrisAnimationDidEndNotification" object:nil];
}
答案 6 :(得分:0)
为了阐述Catalin的回答,(这很棒btw),我发现如果你稍微改变方法“animateIrisOpen”,那么演示文稿会更好......但是很明显。
- (void) animateIrisOpen {
if (iris_) {
iris_.hidden = NO;
[iris_ performSelector:kIrisSelector];
}
}