0

I have a video frame on top of Main.storyboard and I put ScrollView with TextView under that, now my problem is the ScrollView is not in the same position on all devices.

For example, in iPhone 7 Plus its in the correct position but in the iPhone SE its different same iPad.

Here is my ViewController.swift code:

import UIKit
import AVFoundation
import AVKit

class ViewController: UIViewController {

    let playerController = AVPlayerViewController()
    var player:AVPlayer?

    @IBOutlet weak var textView: UITextView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let videoString:String? = Bundle.main.path(forResource: "m9", ofType: ".mov")

        playerController.player = player
        self.addChildViewController(playerController)
        let screenSize = UIScreen.main.bounds.size
        let videoFrame = CGRect(x: 0, y: 30, width: screenSize.width, height: (screenSize.width * 9) / 16 )
        playerController.view.frame = videoFrame
        self.view.addSubview(playerController.view)
        player?.play()

Then I tried to link the ScrollView to video frame:

let frame1 = CGRect(x: 0, y:  350 + videoFrame.height , width: screenSize.width, height: screenSize.height)

textView.frame = frame1
Anh Pham
  • 2,108
  • 9
  • 18
  • 29
Babak
  • 19
  • 4

2 Answers2

0

Just make the outlet of your scrollview and set its frame like :

let scrollViewFrame= CGRect(x: 0, y: playerController.view.frame.maxY, width: screenSize.width, height: replace_actual_height)
scrollView.frame = scrollViewFrame

However, it is better to use autolayout for that rather than setting frames. Here is the link.

Understanding Autolayout

Shubham
  • 763
  • 5
  • 20
0

This code works perfectly in the scroll view. Simple scrollview add in avplayerviewcontoller then don't swipe so replace this code...

 let url = // whatever
 let player = AVPlayer(URL:url)
 let av = AVPlayerViewController()
 av.player = player
 av.view.frame = // whatever
 self.addChildViewController(av)
 self.view.addSubview(av.view)
 av.didMoveToParentViewController(self)

Code is HERE

Raksha Saini
  • 604
  • 12
  • 28