1
votes

I have video view (parent) and a nested view with controls (fullscreen button)

I basically am trying to make a fullscreen button where the view rotates and becomes full screen. The parent view does this without any problems, but the child view is not obeying the constraints. It rotates with the parent but the widths and position do not accommodate the transform.

The child view needs to be pinned to leading + trailing + bottom. With a fixed height.

The parent view is also contained within a containing view.

(The videoView is the parent view)

UIView.animate(withDuration: 0.6, animations: {

            //Set the default frames ready to restore..
            self.videoViewFrame = self.videoView.frame
            self.videoViewButtonFrame = self.videoButtonView.frame


            self.navigationController?.navigationBar.layer.zPosition = -1
            self.navigationController?.setNavigationBarHidden(true, animated: true)

            self.tabBarController?.tabBar.layer.zPosition = -1
            self.tabBarController?.tabBar.isHidden = true


            self.videoView.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI / 2))

            self.videoView.frame = UIScreen.main.bounds

            UIApplication.shared.keyWindow?.windowLevel = UIWindowLevelStatusBar
        }

I have tried different constraint settings.

  • Setting the Leading, trailing and bottom
  • Setting the equal widths and centre within the videoView parent

The child view rotates with the parent, but not constrained to the bottom, left, right as needed.

Here is the cropped smaller view within the controller (portrait)

Here is the fullscreen, with the controls not pinned as needed enter image description here

If i log the constraints of the child view, the constraints are still there after the animation. There is no errors within the log either But if i try to change the frame of the child view, it won't let me. It seems the constraints are stuck at the position before the transform takes place? setNeedsLayout or setNeedsUpdateConstraints doesn't change anything

1
interesting.. you use storyboards or programmatic approach? - Milan Nosáľ
I use storyboards, i think i have found the solution below - nicwhitts
what a pity.. I was hoping for a good challenge :) - Milan Nosáľ
Haha! Thanks anyway - nicwhitts

1 Answers

1
votes

Turns out i needed to use autoresizingMask

self.videoButtonView.translatesAutoresizingMaskIntoConstraints = true
self.videoButtonView.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]

self.fullScreenButton.translatesAutoresizingMaskIntoConstraints = true
self.fullScreenButton.autoresizingMask = [.flexibleLeftMargin]