我尝试向 player.view.subviews[0] 添加滑动手势。
我用谷歌搜索了很多次,但找不到有效的解决方案。
我的代码很正常。就像
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
UIView *subView = player.view.subviews[0];
[subView addGestureRecognizer:swipeLeft];
当播放器处于全屏模式时,它在 IOS5 中有效,但在 6 中无效。 有什么建议吗?
最佳答案
当 Mpmovieplaertsontroller 进入全屏模式时,它会创建一个附加窗口(通常是应用程序窗口列表中的最后一个窗口)。由此我们可以测试所有可能的 View 和 subview 并找到必要的控件。然后你就可以放置你需要的一切了。 例如,如何向 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];
}
关于objective-c - 如何在 IOS6 中的全屏模式 MPMoviePlayerController 上添加滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17247173/