Search code examples
iosuiviewmpmovieplayercontrolleruitouch

UITouch blocked after using MPMoviePlayerController's view


I have a UIButton at the top left of the screen. Using iOS simulator, I can easily touch the farthest most top left part of the button. It works as expected:

enter image description here

But after using MPMoviePlayerController, the button doesn't work when pressed in that region! (can be a bit bigger/smaller). Sounds crazy!

MPMoviePlayerController Code:

if (!_player) {
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];        

    NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryErr];
    [[AVAudioSession sharedInstance] setActive: YES error: &activationErr];

    VCRoot* root = [[ApplicationManager sharedManager] rootViewController];

    _player = [[MPMoviePlayerController alloc] init];
    _player.movieSourceType = MPMovieSourceTypeStreaming;
    _player.view.hidden = YES;
    [root.view addSubview:_player.view];

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(moviePlayerStateChanged:) 
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:nil];
} else {
    [_player stop];
}

_player.contentURL = [channel url];

[_player setInitialPlaybackTime:-1.0];
[_player play];

NOTE:

I tried adding the _player.view using insertSubview: AtIndex:0, tried setIsUserInteractionEnabled = NO, tried setAlpha = 0.f, all no use .. I even added it as a subview of a different view.

HOWEVER:

When I stop the player, and remove the view, that area is touchable again :(


Solution

  • Out of all the things I tried ... Finally:

    _player.view.frame = CGRectMake(-100, -100, 1.f, 1.f);

    worked!