我在Main.storyboard上面有一个视频帧,我把ScrollView和TextView放在一起,现在我的问题是ScrollView在所有设备上的位置不同。
例如,在iPhone 7 Plus中它处于正确的位置,但在iPhone SE中它的iPad却不同。
这是我的ViewController.swift代码:
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()
然后我尝试将ScrollView链接到视频帧:
let frame1 = CGRect(x: 0, y: 350 + videoFrame.height , width: screenSize.width, height: screenSize.height)
textView.frame = frame1
答案 0 :(得分:0)
只需制作滚动视图的插座并将其框架设置为:
Checkbox check1 = new Checkbox(getApplicationContext());
check1.setLayoutParams(new ActionBar.LayoutParams(LinearLayoutCompat.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
check1.setId(fieldNo);
check1.setTextColor(Color.BLACK);
check1.setGravity(Gravity.RIGHT);
check1.setText(formField.get(fieldNo));
但是,最好使用autolayout而不是设置帧。这是链接。
答案 1 :(得分:0)
此代码在滚动视图中完美运行。简单的scrollview添加avplayerviewcontoller然后不要刷卡,所以替换此代码......
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)
代码为HERE