简体   繁体   English

如何在可滚动视图上修复AVPlayer位置或如何在视图中修复它

[英]How to fix AVPlayer position on scrollable view or How to fix it in a view

Do anybody have idea about how to fix AVPlayer position on a scroll-able view i am using the following code to set the AVPlayer frame but when the device size changes it remains of same size on different size and also i have a scrollable view so because of this code i am using the view scrolls in background and player remains fix at a place. 有人知道如何在可滚动视图上固定AVPlayer位置吗?我正在使用以下代码来设置AVPlayer框架,但是当设备大小更改时,它在不同大小上仍保持相同的大小,而且我有一个可滚动视图,因此这段代码是我在后台使用视图滚动条,播放器仍固定在某个位置。 Any help is appreciated. 任何帮助表示赞赏。

   //here is my code

     - (void)viewDidLoad {
          [super viewDidLoad];

    NSString *localfilepath=[NSString stringWithFormat:@"%@",[managedObject valueForKey:@"clip_path"]];

    player = [AVPlayer playerWithURL:url];

    AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];

   [self addChildViewController:controller];
   [self.view addSubview:controller.view];

   controller.view.frame = CGRectMake(10,80,300,250);
   controller.player = player;
   controller.showsPlaybackControls = YES;

   [player pause];

 }

like this: 像这样:

1.your view controller conforms to UIScrollViewDelegate protocol 1.您的视图控制器符合UIScrollViewDelegate协议
2.in - (void)viewDidLoad, set your scroll view's delegate to self, like 2.在-(void)viewDidLoad中,将滚动视图的委托设置为self,例如

self.scrollView.delegate = self;

3.implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView, for example 3.实现-(void)scrollViewDidScroll:(UIScrollView *)scrollView

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint offset = scrollView.contentOffset;
    UIView *avplayerView = [self getAVPlayerView];
    avplayerView.frame = CGRectMake(10, 80 + offset.y, 300, 250);
}

Hope this helpful 希望对您有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM