gpt4 book ai didi

ios - 自定义按钮在AVPlayer iOS 11中不起作用,但在iOS 11以下完全可以工作吗?

转载 作者:行者123 更新时间:2023-12-01 18:38:52 30 4
gpt4 key购买 nike

我知道这可能是重复的问题,但是已经存在的问题没有解决的办法,因此,我再次要求提出赏金问题。

这是我的代码,它在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函数。
任何帮助,将不胜感激 !

最佳答案

@DeepShah您已在avcontroller.view中添加了跳过按钮,因此其显示正确,但您无法单击它,因为AVPlayerViewControllerContentView覆盖了该跳过按钮。

参见下图:

image

因此您必须在self.view及其作品中添加跳过按钮。

[self.view addSubview:_skip];
[self.view bringSubviewToFront:_skip];

关于ios - 自定义按钮在AVPlayer iOS 11中不起作用,但在iOS 11以下完全可以工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46871529/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com