How do I intercept tapping of the done button in AVPlayerViewController?

前端 未结 10 718
渐次进展
渐次进展 2021-01-03 22:45

I created an AVPlayerViewController and an attached AVPlayer in the viewDidAppear method of a custom UIViewController. Ho

10条回答
  •  半阙折子戏
    2021-01-03 23:07

    Here is code how I managed to detect clicks.

    In application delegate class. But it detects every buttons find in that view. You can add some control, check title something like that.

    -(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
        if ([window.rootViewController isKindOfClass:[AVPlayerViewController class]]) {
            return UIInterfaceOrientationMaskAll;
        }
        else if(window.rootViewController.presentedViewController != nil)
        {
            if ([window.rootViewController.presentedViewController isKindOfClass:[AVPlayerViewController class]] || [window.rootViewController.presentedViewController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
                if ([window.rootViewController.presentedViewController isKindOfClass:NSClassFromString(@"AVFullScreenViewController")]) {
                    [self findAllButton:window.rootViewController.presentedViewController.view];
                }
                return UIInterfaceOrientationMaskAll;
            }
        }
        [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
        [[UIApplication sharedApplication] setStatusBarHidden:NO];
        return UIInterfaceOrientationMaskPortrait;
    }
    
    -(void)findAllButton:(UIView*)view{
        for (UIView *subV in view.subviews) {
            if ([subV isKindOfClass:[UIButton class]]) {
                NSLog(@"%@",[((UIButton*)subV) titleForState:UIControlStateNormal]);
                [((UIButton*)subV) addTarget:self action:@selector(doneButtonCliked) forControlEvents:UIControlEventTouchUpInside];
            }
            else{
                [self findAllButton:subV];
            }
        }
    }
    -(IBAction)doneButtonCliked{
        NSLog(@"DONECLICK");
    }
    

提交回复
热议问题