简体   繁体   中英

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. 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
2.in - (void)viewDidLoad, set your scroll view's delegate to self, like

self.scrollView.delegate = self;

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

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

Hope this helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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