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

时间:2016-06-08 12:18:12

标签: ios avplayer cgrectmake avplayerviewcontroller

有没有人知道如何在可滚动视图上修复AVPlayer位置我使用以下代码来设置AVPlayer帧但是当设备大小改变时,它在不同大小上保持相同的大小并且我还有一个可滚动的查看因为这个代码我使用视图滚动在后台,玩家仍然在一个地方修复。任何帮助表示赞赏。

   //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];

 }

1 个答案:

答案 0 :(得分:0)

像这样:

1.您的视图控制器符合UIScrollViewDelegate协议
2.in - (void)viewDidLoad,将滚动视图的委托设置为self,如

self.scrollView.delegate = self;

3.implement - (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);
}

希望这有用