自定义按钮在AVPlayer iOS 11中不起作用,但它在iOS 11下完美运行? [英] Custom button not working in AVPlayer iOS 11 but it's perfectly working below iOS 11?
问题描述
我知道这可能是重复的问题,但已经存在的问题没有解决方案,所以我再次要求可能开始赏金问题。
I know possibly this is duplicate question but the question which is already exist didn't have an solution so , I'm asking again to possibly start bounty question .
这是我的代码在iOS 11下工作:
Here is my code which is working below iOS 11 :
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
avcontroller = [[AVPlayerViewController alloc]init];
avcontroller.player = player;
[player play];
NSNotificationCenter *noteCenter = [NSNotificationCenter defaultCenter];
[noteCenter addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSLog(@"Video end");
self.avcontroller.player = nil;
[self.avcontroller.view removeFromSuperview];
[self.view addSubview:delegate.tabViewControllerObj.tabBarController.view];
}];
_skip =[UIButton buttonWithType:UIButtonTypeCustom];
[_skip addTarget:self action:@selector(btnSkipTapped)
forControlEvents:UIControlEventTouchUpInside];
[_skip setTitle:@"Skip" forState:UIControlStateNormal];
_skip.layer.borderWidth = 2.0f;
_skip.layer.cornerRadius = 12;
_skip.clipsToBounds = YES;
_skip.layer.borderColor = [UIColor whiteColor].CGColor;
// show the view controller
[self addChildViewController:avcontroller];
[avcontroller.view addSubview:_skip];
[avcontroller.view bringSubviewToFront:_skip];
[self.view addSubview:avcontroller.view];
avcontroller.view.frame = self.view.frame;
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
_skip.frame = CGRectMake((self.view.frame.size.width-140),(self.view.frame.size.height-150),100.0,35.0);
}
这里是按钮点击功能:
- (IBAction)btnSkipTapped{
NSLog(@"Skip button clicked");
self.avcontroller.player = nil;
[self.avcontroller.view removeFromSuperview];
[self.view addSubview:delegate.tabViewControllerObj.tabBarController.view];
}
此代码将完美显示按钮,但按下按钮后,它没有调用btnSkipTapped函数。
任何帮助将不胜感激!
This code will display button perfectly but upon button tap , it didn't call btnSkipTapped function. Any help would be appreciated !
推荐答案
@DeepShah您已在 avcontroller中添加了跳过按钮.view
所以它的显示正常,但你不能点击它,因为 AVPlayerViewControllerContentView
涵盖了跳过按钮。
@DeepShah you have added skip button in avcontroller.view
so its display proper but you can't click on it because AVPlayerViewControllerContentView
covers that skip button.
见下图:
所以你必须在 self.view
中添加跳过按钮及其作品。
so you have to add skip button in self.view
and its works.
[self.view addSubview:_skip];
[self.view bringSubviewToFront:_skip];
这篇关于自定义按钮在AVPlayer iOS 11中不起作用,但它在iOS 11下完美运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!