2017-01-27 1 views
1

AVPlayerLayer을 셀 공간을 채우려 고했지만 프레임 속성을 설정하여 크기가 변경되지 않았습니다. 내 uitableviewcontroller 파일에 다음AVPlayerLayer가 셀 경계로 크기가 변경되지 않습니다.

override init(style: UITableViewCellStyle, reuseIdentifier: String?) { 
    super.init(style: style, reuseIdentifier: reuseIdentifier) 


    let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") 
    let player = AVPlayer(url: videoURL! as URL) 
    let playerLayer = AVPlayerLayer(player: player) 
    playerLayer.frame = contentView.bounds; 
    contentView.layer.addSublayer(playerLayer) 
    player.play() 
} 

:

내 사용자 정의 셀 파일에서

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    let cell = tableView.dequeueReusableCell(withIdentifier: "clipHomeCells", for: indexPath) as! ClipTableViewCell 
    // Configure the cell... 
    return cell 
} 

그러나 그것은 다음과 같습니다

enter image description here

답변

0

CALayer 개체를하지 않습니다 자동으로 크기를 조정하여 뷰를 채 웁니다. 확장 될 때까지 길어라. 따라서 레이어에는 처음에 지정한 프레임과 동일한 프레임이 있습니다. 자동 레이아웃 또는 heightForRow(at:) 대리자 메서드로 인해 셀 크기가 나중에 변경되면 CALayer 프레임이 일치하도록 업데이트되지 않습니다.

내가 과거에 이것을 처리 한 방법은 의 사용자 지정 하위 클래스를 만들어서 CALayer을 관리하고 layoutSubviews()에 적절하게 크기를 지정하는 것입니다.

+0

@wtfislife,이 답변이 도움이 되었습니까? –