HomeiOS Developmentios - Centering a CALayer Horizontally Inside UIView

ios – Centering a CALayer Horizontally Inside UIView


Because the title says, I’ve gotten my video participant to work, nevertheless it exhibits the video on the precise facet of the cell as an alternative of centered. Unsure why, I’ve tried a number of issues on the web, and I do know my code might be not wonderful, however I simply wish to heart it horizontally and it refuses to work with me. If I flip off playerView.translatesAutoresizingMaskIntoConstraints = false it simply outright disappears

img_thumb is a picture that takes up everything of the area that can be a video thumbnail earlier than it hundreds however proper now’s only a black background for the video, both manner the complete contentView has an extra component on the backside so it is simpler to make use of the img_thumb constraints

    playerView.body = videoCell.img_thumb.body
//                            playerView.layer.bounds = videoCell.img_thumb.bounds
//                            playerView.layer.body = videoCell.img_thumb.body
    playerView.layer.place = CGPoint(x: videoCell.img_thumb.bounds.midX, y: videoCell.img_thumb.bounds.midY)
    videoCell.contentView.addSubview(playerView)
    playerView.translatesAutoresizingMaskIntoConstraints = false
    playerView.bounds = videoCell.img_thumb.bounds
    playerView.heart = videoCell.img_thumb.heart
    playerView.centerXAnchor.constraint(equalTo: videoCell.img_thumb.centerXAnchor).isActive = true
    playerView.centerYAnchor.constraint(equalTo: videoCell.img_thumb.centerYAnchor).isActive = true
    playerView.heightAnchor.constraint(lessThanOrEqualTo: videoCell.img_thumb.heightAnchor).isActive = true
    playerView.widthAnchor.constraint(lessThanOrEqualTo: videoCell.img_thumb.widthAnchor).isActive = true

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments