簡體   English   中英

隱藏/顯示iPhone相機光圈/快門動畫

[英]Hide/Show iPhone Camera Iris/Shutter animation

我無法為我的應用隱藏“ 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)遍歷每一層

希望對您有幫助。

問候,

安庫爾

這個答案為起點,我終於解決了這個問題:

注意:這顯然不兼容3.3.1。

  1. 在您的UIImagePickerController上偵聽UINavigationControllerDidShowViewControllerNotification PLCameraViewIrisAnimationDidEndNotification ,並在全局上偵聽PLCameraViewIrisAnimationDidEndNotification

  2. 遍歷視圖層次結構(從主UIWindow )以查找PLCameraView 將視圖的索引保存在主UIWindow ,以備后用。

  3. 取出PLCameraViewsuperView 如果需要,在全局索引0處插入您自己的視圖。

  4. 虹膜動畫完成后,請移開視圖,然后以其原始索引重新添加PLCameraView

遇到了類似的情況:我想讓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
}

為了詳細說明Catalin的答案(順便說一句),我發現如果您稍微更改方法“ animateIrisOpen”,則表示效果會好一些……但值得注意。

- (void) animateIrisOpen {
    if (iris_) {
        iris_.hidden = NO;
        [iris_ performSelector:kIrisSelector];
    }
}

我已經弄亂了一點,但是將視圖生命周期方法的各種組合發送到圖像選擇器。 (viewWillAppear,viewDidAppear等),但是我不記得哪個最終可以工作。

很抱歉回復這么晚。 我找到了解決好我使用cameraView的視圖層次結構的解決方案,並在所有內容的頂部添加了自己的圖層。 動畫在那里發生,一旦快門打開,最頂層將被移除。 如果有人需要進一步的幫助,請告訴我,我將提供確切的步驟和語法。

-安庫爾

在照相機光圈動畫開始之前,將調用以下功能。

- (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)遍歷每一層

希望對您有幫助。

問候,

安庫爾

在虹膜動畫的持續時間內,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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM