echo echo - 6 months ago 30
Objective-C Question

How to add swipe gesture on a fullscreen mode MPMoviePlayerController in IOS6

I tried to add a swipe gesture to


I googled for many times but could not get a working solution.

My code is very normal. just like

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
UIView *subView = player.view.subviews[0];
[subView addGestureRecognizer:swipeLeft];

It works in IOS5 but not in 6 when player is in fullscreen mode.
Any suggestions?


When Mpmovieplaertsontroller enters full-screen mode, it creates an additional window (usually the last in the list of application windows). From this we can test all possible views and subviews and find the necessary controls. Then you can put everything you need. For example, how to add swipes to the MPMoviePlayer.

- (void)didEnterFullScreen:(NSNotification*)notification {
    [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(showFullScreenControls) userInfo:nil repeats:NO];

- (void)showFullScreenControls {
    NSArray *windows = [[UIApplication sharedApplication] windows];
    UIWindow* mpfullscreenwindow = [windows lastObject];
    gestureView = mpfullscreenwindow.subviews[0];
    testbutton = [UIButton buttonWithType:UIButtonTypeSystem];
    [testbutton setTitle:@"Test" forState:UIControlStateNormal];
    testbutton.frame = CGRectMake(10, 50, 100, 50);
    testbutton.backgroundColor = [UIColor greenColor];
    [testbutton addTarget:self action:@selector(alertBtnAction) forControlEvents: UIControlEventTouchUpInside];
    [mpfullscreenwindow addSubview:testbutton];
    [gestureView addGestureRecognizer:_leftSwipeRecognizer];
    [gestureView addGestureRecognizer:_rightSwipeRecognizer];